1 /* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 20222 Intel Corporation. All rights reserved.
4 */
5
6 #ifndef __ZEPHYR_RTOS_STRING_H__
7 #define __ZEPHYR_RTOS_STRING_H__
8
9 /* Zephyr uses a C library so lets use it */
10 #include <string.h>
11 #include <stddef.h>
12 #include <errno.h>
13
14 void *__vec_memcpy(void *dst, const void *src, size_t len);
15 void *__vec_memset(void *dest, int data, size_t src_size);
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 /* missing from zephyr - TODO: convert to memset() */
21 #define bzero(ptr, size) \
22 memset(ptr, 0, size)
23
24 /* TODO: need converted to C library calling conventions */
rstrlen(const char * s)25 static inline int rstrlen(const char *s)
26 {
27 return strlen(s);
28 }
29
30 /* TODO: need converted to C library calling conventions */
rstrcmp(const char * s1,const char * s2)31 static inline int rstrcmp(const char *s1, const char *s2)
32 {
33 return strcmp(s1, s2);
34 }
35
36 /* C library does not have the "_s" versions used by Windows */
memcpy_s(void * dest,size_t dest_size,const void * src,size_t count)37 static inline int memcpy_s(void *dest, size_t dest_size,
38 const void *src, size_t count)
39 {
40 if (!dest || !src)
41 return -EINVAL;
42
43 if ((dest >= src && (char *)dest < ((char *)src + count)) ||
44 (src >= dest && (char *)src < ((char *)dest + dest_size)))
45 return -EINVAL;
46
47 if (count > dest_size)
48 return -EINVAL;
49
50 memcpy(dest, src, count);
51
52 return 0;
53 }
54
memset_s(void * dest,size_t dest_size,int data,size_t count)55 static inline int memset_s(void *dest, size_t dest_size, int data, size_t count)
56 {
57 if (!dest)
58 return -EINVAL;
59
60 if (count > dest_size)
61 return -EINVAL;
62
63 if (!memset(dest, data, count))
64 return -ENOMEM;
65
66 return 0;
67 }
68
69 #ifdef __cplusplus
70 } /* extern "C" */
71 #endif
72
73 #endif /* __ZEPHYR_RTOS_STRING_H__ */
74