195fed0d3SAxel Dörfler#ifndef _LIBC_STRING_H
295fed0d3SAxel Dörfler#define _LIBC_STRING_H
395fed0d3SAxel Dörfler
495fed0d3SAxel Dörfler#include_next <string.h>
595fed0d3SAxel Dörfler
695fed0d3SAxel Dörfler/* map the internal glibc interface to the public one */
795fed0d3SAxel Dörfler#define __memcpy(to, from, size)	memcpy(to, from, size)
895fed0d3SAxel Dörfler#define __strchrnul(string, character)	strchrnul(string, character)
9a6508c73SJérôme Duval#define __strnlen			strnlen
1087e239b9SJérôme Duval#define __strdup			strdup
1187e239b9SJérôme Duval#define __strndup			strndup
1287e239b9SJérôme Duval#define __stpcpy			stpcpy
1387e239b9SJérôme Duval#define __strtok_r			strtok_r
1487e239b9SJérôme Duval#define __strcasecmp			strcasecmp
15c713cfe2SAxel Dörfler
16c713cfe2SAxel Dörflerstatic inline char *
17c713cfe2SAxel Dörfler__strerror_r(int error, char *buffer, size_t bufferSize)
18c713cfe2SAxel Dörfler{
19c713cfe2SAxel Dörfler	if (strerror_r(error, buffer, bufferSize) != 0)
20c713cfe2SAxel Dörfler		strlcpy(buffer, "Unknown Error", bufferSize);
21c713cfe2SAxel Dörfler
22c713cfe2SAxel Dörfler	return buffer;
23c713cfe2SAxel Dörfler}
2495fed0d3SAxel Dörfler
2595fed0d3SAxel Dörflerstatic inline void *
2695fed0d3SAxel Dörfler__mempcpy(void *to, const void *from, size_t size)
2795fed0d3SAxel Dörfler{
2895fed0d3SAxel Dörfler	memcpy(to, from, size);
2995fed0d3SAxel Dörfler	return (unsigned char *)to + size;
3095fed0d3SAxel Dörfler}
3195fed0d3SAxel Dörfler
3287e239b9SJérôme Duval#undef strdupa
3387e239b9SJérôme Duval#define strdupa(s)                                                           \
3487e239b9SJérôme Duval  (__extension__                                                              \
3587e239b9SJérôme Duval    ({                                                                        \
3687e239b9SJérôme Duval      __const char *__old = (s);                                              \
3787e239b9SJérôme Duval      size_t __len = strlen (__old) + 1;                                      \
3887e239b9SJérôme Duval      char *__new = (char *) __builtin_alloca (__len);                        \
3987e239b9SJérôme Duval      (char *) memcpy (__new, __old, __len);                                  \
4087e239b9SJérôme Duval    }))
4187e239b9SJérôme Duval
4287e239b9SJérôme Duval/* Alternative version which doesn't pollute glibc's namespace.  */
4387e239b9SJérôme Duval#undef strndupa
4487e239b9SJérôme Duval#define strndupa(s, n)                                                        \
4587e239b9SJérôme Duval  (__extension__                                                              \
4687e239b9SJérôme Duval    ({                                                                        \
4787e239b9SJérôme Duval      __const char *__old = (s);                                              \
4887e239b9SJérôme Duval      size_t __len = __strnlen (__old, (n));                                  \
4987e239b9SJérôme Duval      char *__new = (char *) __builtin_alloca (__len + 1);                    \
5087e239b9SJérôme Duval      __new[__len] = '\0';                                                    \
5187e239b9SJérôme Duval      (char *) memcpy (__new, __old, __len);                                  \
5287e239b9SJérôme Duval    }))
5387e239b9SJérôme Duval
5495fed0d3SAxel Dörfler#endif	/* _LIBC_STRING_H */