• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "hvb_sysdeps.h"
16 #include <string.h>
17 
18 #ifdef LOG_TAG
19 #undef LOG_TAG
20 #endif
21 
22 #define LOG_TAG "libhvb"
23 
hvb_memcmp(const void * src1,const void * src2,size_t n)24 int hvb_memcmp(const void *src1, const void *src2, size_t n)
25 {
26     return memcmp(src1, src2, n);
27 }
28 
hvb_memcpy(void * dest,const void * src,size_t n)29 void *hvb_memcpy(void *dest, const void *src, size_t n)
30 {
31     return memcpy(dest, src, n);
32 }
33 
hvb_memcpy_s(void * dest,size_t destMax,const void * src,size_t count)34 int hvb_memcpy_s(void *dest, size_t destMax, const void *src, size_t count)
35 {
36     return memcpy_s(dest, destMax, src, count);
37 }
38 
hvb_memset(void * dest,const int c,size_t n)39 void *hvb_memset(void *dest, const int c, size_t n)
40 {
41     return memset(dest, c, n);
42 }
43 
hvb_memset_s(void * dest,size_t destMax,int c,size_t count)44 int hvb_memset_s(void *dest, size_t destMax, int c, size_t count)
45 {
46     return memset_s(dest, destMax, c, count);
47 }
48 
hvb_strcmp(const char * s1,const char * s2)49 int hvb_strcmp(const char *s1, const char *s2)
50 {
51     return strcmp(s1, s2);
52 }
53 
hvb_strncmp(const char * s1,const char * s2,size_t n)54 int hvb_strncmp(const char *s1, const char *s2, size_t n)
55 {
56     return strncmp(s1, s2, n);
57 }
58 
hvb_strlen(const char * str)59 size_t hvb_strlen(const char *str)
60 {
61     return (size_t)strlen(str);
62 }
63 
hvb_strnlen(const char * str,size_t len)64 size_t hvb_strnlen(const char *str, size_t len)
65 {
66     return (size_t)strnlen(str, len);
67 }
68 
hvb_abort(void)69 void hvb_abort(void)
70 {
71     printf("ERROR, an error happened\n");
72 }
73 
hvb_print(const char * message)74 void hvb_print(const char *message)
75 {
76     printf("%s\n", message);
77 }
78 
hvb_print_u64(uint64_t num)79 void hvb_print_u64(uint64_t num)
80 {
81     printf("0x%lx,", num);
82 }
83 
hvb_printv(const char * message,...)84 void hvb_printv(const char *message, ...)
85 {
86     va_list ap;
87     const char *msg;
88 
89     va_start(ap, message);
90     for (msg = message; msg != NULL; msg = va_arg(ap, const char*)) {
91         printf("%s", msg);
92     }
93     va_end(ap);
94 }
95 
hvb_malloc_(size_t size)96 void *hvb_malloc_(size_t size)
97 {
98     if (size == 0) {
99         hvb_print("size is invalid");
100         return NULL;
101     }
102     return malloc(size);
103 }
104 
hvb_free(void * ptr)105 void hvb_free(void *ptr)
106 {
107     if (ptr != NULL) {
108         free(ptr);
109     }
110 }
111 
hvb_div_by_10(uint64_t * dividend)112 uint32_t hvb_div_by_10(uint64_t *dividend)
113 {
114     uint32_t rem = (uint32_t)(*dividend % 10);
115     *dividend /= 10;
116     return rem;
117 }
118