xref: /haiku/src/system/libroot/posix/glibc/include/string.h (revision 87e239b9dc52a9627ba19bf5b8a8bc41627ea04c)
1 #ifndef _LIBC_STRING_H
2 #define _LIBC_STRING_H
3 
4 #include_next <string.h>
5 
6 /* map the internal glibc interface to the public one */
7 #define __memcpy(to, from, size)	memcpy(to, from, size)
8 #define __strchrnul(string, character)	strchrnul(string, character)
9 #define __strnlen			strnlen
10 #define __strdup			strdup
11 #define __strndup			strndup
12 #define __stpcpy			stpcpy
13 #define __strtok_r			strtok_r
14 #define __strcasecmp			strcasecmp
15 
16 static inline char *
__strerror_r(int error,char * buffer,size_t bufferSize)17 __strerror_r(int error, char *buffer, size_t bufferSize)
18 {
19 	if (strerror_r(error, buffer, bufferSize) != 0)
20 		strlcpy(buffer, "Unknown Error", bufferSize);
21 
22 	return buffer;
23 }
24 
25 static inline void *
__mempcpy(void * to,const void * from,size_t size)26 __mempcpy(void *to, const void *from, size_t size)
27 {
28 	memcpy(to, from, size);
29 	return (unsigned char *)to + size;
30 }
31 
32 #undef strdupa
33 #define strdupa(s)                                                           \
34   (__extension__                                                              \
35     ({                                                                        \
36       __const char *__old = (s);                                              \
37       size_t __len = strlen (__old) + 1;                                      \
38       char *__new = (char *) __builtin_alloca (__len);                        \
39       (char *) memcpy (__new, __old, __len);                                  \
40     }))
41 
42 /* Alternative version which doesn't pollute glibc's namespace.  */
43 #undef strndupa
44 #define strndupa(s, n)                                                        \
45   (__extension__                                                              \
46     ({                                                                        \
47       __const char *__old = (s);                                              \
48       size_t __len = __strnlen (__old, (n));                                  \
49       char *__new = (char *) __builtin_alloca (__len + 1);                    \
50       __new[__len] = '\0';                                                    \
51       (char *) memcpy (__new, __old, __len);                                  \
52     }))
53 
54 #endif	/* _LIBC_STRING_H */
55