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_printv(const char * message,...)79 void hvb_printv(const char *message, ...)
80 {
81 va_list ap;
82 const char *msg;
83
84 va_start(ap, message);
85 for (msg = message; msg != NULL; msg = va_arg(ap, const char*)) {
86 printf("%s", msg);
87 }
88 va_end(ap);
89 }
90
hvb_malloc_(size_t size)91 void *hvb_malloc_(size_t size)
92 {
93 return malloc(size);
94 }
95
hvb_free(void * ptr)96 void hvb_free(void *ptr)
97 {
98 if (ptr != NULL) {
99 free(ptr);
100 }
101 }
102
hvb_div_by_10(uint64_t * dividend)103 uint32_t hvb_div_by_10(uint64_t *dividend)
104 {
105 uint32_t rem = (uint32_t)(*dividend % 10);
106 *dividend /= 10;
107 return rem;
108 }
109