From 4dd29ad13268a9dfec24e4be4ad6304a05bed709 Mon Sep 17 00:00:00 2001 From: Manuel Novoa III Date: Thu, 28 Jul 2005 03:36:45 +0000 Subject: Fix string.h. Change our _susv3_strerror_r to __xpg_strerror_r for glibc compatibility. Also change _glibc_strerror_r to __glibc_strerror_r for consistency. --- include/string.h | 63 ++++++++++++++++++++++++++++------------------- libc/misc/error/err.c | 2 +- libc/stdio/old_vfprintf.c | 2 +- libc/stdio/perror.c | 2 +- libc/stdio/vfprintf.c | 2 +- libc/string/Makefile | 4 +-- libc/string/wstring.c | 16 ++++++------ 7 files changed, 51 insertions(+), 40 deletions(-) diff --git a/include/string.h b/include/string.h index 880290287..224bb8621 100644 --- a/include/string.h +++ b/include/string.h @@ -122,13 +122,13 @@ __END_NAMESPACE_STD extern int strcoll_l (__const char *__s1, __const char *__s2, __locale_t __l) __THROW __attribute_pure__ __nonnull ((1, 2, 3)); extern int __strcoll_l (__const char *__s1, __const char *__s2, __locale_t __l) - __THROW __attribute_pure__; + __THROW __attribute_pure__ __nonnull ((1, 2, 3)); /* Put a transformation of SRC into no more than N bytes of DEST. */ extern size_t strxfrm_l (char *__dest, __const char *__src, size_t __n, __locale_t __l) __THROW __nonnull ((2, 4)); extern size_t __strxfrm_l (char *__dest, __const char *__src, size_t __n, - __locale_t __l) __THROW; + __locale_t __l) __THROW __nonnull ((2, 4)); #endif #endif /* __UCLIBC_HAS_XLOCALE__ */ @@ -263,33 +263,41 @@ __BEGIN_NAMESPACE_STD /* Return a string describing the meaning of the `errno' code in ERRNUM. */ extern char *strerror (int __errnum) __THROW; __END_NAMESPACE_STD + +extern char *__glibc_strerror_r (int __errnum, char *__buf, size_t __buflen) + __THROW __nonnull ((2)); +extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen) + __THROW __nonnull ((2)); + #if defined __USE_XOPEN2K || defined __USE_MISC -/* Reentrant version of `strerror'. If a temporary buffer is required, at - most BUFLEN bytes of BUF will be used. */ -/* extern char *strerror_r (int __errnum, char *__buf, size_t __buflen) __THROW; */ - -/* uClibc Note: glibc's strerror_r is different from that specified in SUSv3. - * So we try to compensate based on feature macros. */ -extern char *_glibc_strerror_r (int __errnum, char *__buf, size_t __buflen) __THROW; -extern int _susv3_strerror_r (int __errnum, char *__buf, size_t buflen) __THROW; - -# if defined(__USE_XOPEN2K) && !defined(__USE_GNU) -# ifdef __REDIRECT -extern int __REDIRECT (strerror_r, - (int __errnum, char *__buf, size_t buflen) __THROW, - _susv3_strerror_r); +/* Reentrant version of `strerror'. + There are 2 flavors of `strerror_r', GNU which returns the string + and may or may not use the supplied temporary buffer and POSIX one + which fills the string into the buffer. + To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L + without -D_GNU_SOURCE is needed, otherwise the GNU version is + preferred. */ +# if defined __USE_XOPEN2K && !defined __USE_GNU +/* Fill BUF with a string describing the meaning of the `errno' code in + ERRNUM. */ +# ifdef __REDIRECT_NTH +extern int __REDIRECT_NTH (strerror_r, + (int __errnum, char *__buf, size_t __buflen), + __xpg_strerror_r) __nonnull ((2)); # else # define strerror_r __xpg_strerror_r # endif # else -# ifdef __REDIRECT -extern char *__REDIRECT (strerror_r, - (int __errnum, char *__buf, size_t buflen) __THROW, - _glibc_strerror_r); +/* If a temporary buffer is required, at most BUFLEN bytes of BUF will be + used. */ +# ifdef __REDIRECT_NTH +extern char * __REDIRECT_NTH (strerror_r, + (int __errnum, char *__buf, size_t __buflen), + __glibc_strerror_r) __nonnull ((2)); # else -# define strerror_r _glibc_strerror_r +# define strerror_r __glibc_strerror_r # endif -# endif /* defined(__USE_XOPEN2K) && !defined(__USE_GNU) */ +# endif #endif /* We define this function always since `bzero' is sometimes needed when @@ -347,14 +355,15 @@ extern int strcasecmp_l (__const char *__s1, __const char *__s2, __locale_t __loc) __THROW __attribute_pure__ __nonnull ((1, 2, 3)); extern int __strcasecmp_l (__const char *__s1, __const char *__s2, - __locale_t __loc) __THROW __attribute_pure__; + __locale_t __loc) + __THROW __attribute_pure__ __nonnull ((1, 2, 3)); extern int strncasecmp_l (__const char *__s1, __const char *__s2, size_t __n, __locale_t __loc) __THROW __attribute_pure__ __nonnull ((1, 2, 4)); extern int __strncasecmp_l (__const char *__s1, __const char *__s2, size_t __n, __locale_t __loc) - __THROW __attribute_pure__; + __THROW __attribute_pure__ __nonnull ((1, 2, 4)); #endif #endif /* __UCLIBC_HAS_XLOCALE__ */ @@ -389,11 +398,13 @@ extern char *stpncpy (char *__restrict __dest, __const char *__restrict __src, size_t __n) __THROW __nonnull ((1, 2)); +#if 0 /* uClibc does not support strfry or memfrob. */ /* Sautee STRING briskly. */ extern char *strfry (char *__string) __THROW __nonnull ((1)); /* Frobnicate N bytes of S. */ extern void *memfrob (void *__s, size_t __n) __THROW __nonnull ((1)); +#endif # ifndef basename /* Return the file name within directory of FILENAME. We don't @@ -408,9 +419,9 @@ extern char *basename (__const char *__filename) __THROW __nonnull ((1)); #ifdef __USE_BSD /* Two OpenBSD extension functions. */ extern size_t strlcat(char *__restrict dst, const char *__restrict src, - size_t n) __THROW; + size_t n) __THROW __nonnull ((1, 2)); extern size_t strlcpy(char *__restrict dst, const char *__restrict src, - size_t n) __THROW; + size_t n) __THROW __nonnull ((1, 2)); #endif __END_DECLS diff --git a/libc/misc/error/err.c b/libc/misc/error/err.c index 5c53e545f..0d0637148 100644 --- a/libc/misc/error/err.c +++ b/libc/misc/error/err.c @@ -34,7 +34,7 @@ static void vwarn_work(const char *format, va_list args, int showerr) f = fmt + 11; /* At 11. */ if (showerr) { f -= 4; /* At 7. */ - _susv3_strerror_r(errno, buf, sizeof(buf)); + __xpg_strerror_r(errno, buf, sizeof(buf)); } __STDIO_AUTO_THREADLOCK(stderr); diff --git a/libc/stdio/old_vfprintf.c b/libc/stdio/old_vfprintf.c index 1b7af96f9..23cb10f94 100644 --- a/libc/stdio/old_vfprintf.c +++ b/libc/stdio/old_vfprintf.c @@ -448,7 +448,7 @@ int vfprintf(FILE * __restrict op, register const char * __restrict fmt, if (*fmt == 'm') { flag[FLAG_PLUS] = '\0'; flag[FLAG_0_PAD] = ' '; - p = _glibc_strerror_r(errno, tmp, sizeof(tmp)); + p = __glibc_strerror_r(errno, tmp, sizeof(tmp)); goto print; } #endif diff --git a/libc/stdio/perror.c b/libc/stdio/perror.c index 83db7689f..26a0cebd9 100644 --- a/libc/stdio/perror.c +++ b/libc/stdio/perror.c @@ -30,7 +30,7 @@ void perror(register const char *s) { char buf[64]; fprintf(stderr, "%s%s%s\n", s, sep, - _glibc_strerror_r(errno, buf, sizeof(buf))); + __glibc_strerror_r(errno, buf, sizeof(buf))); } #endif } diff --git a/libc/stdio/vfprintf.c b/libc/stdio/vfprintf.c index d3214fff0..dbc7c7cf2 100644 --- a/libc/stdio/vfprintf.c +++ b/libc/stdio/vfprintf.c @@ -1708,7 +1708,7 @@ static int _do_one_spec(FILE * __restrict stream, #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__ } else if (ppfs->conv_num == CONV_m) { - s = _glibc_strerror_r(errno, buf, sizeof(buf)); + s = __glibc_strerror_r(errno, buf, sizeof(buf)); goto SET_STRING_LEN; #endif } else { diff --git a/libc/string/Makefile b/libc/string/Makefile index 111bf2fdb..6b516c1c5 100644 --- a/libc/string/Makefile +++ b/libc/string/Makefile @@ -39,8 +39,8 @@ MOBJ= basename.o bcopy.o bzero.o dirname.o ffs.o memccpy.o memchr.o memcmp.o \ stpncpy.o strcasecmp.o strcasestr.o strcat.o strchrnul.o strchr.o \ strcmp.o strcpy.o strcspn.o strdup.o strlen.o strncasecmp.o strncat.o \ strncmp.o strncpy.o strndup.o strnlen.o strpbrk.o strrchr.o strsep.o \ - strspn.o strstr.o strtok.o strtok_r.o strerror.o _susv3_strerror_r.o \ - _string_syserrmsgs.o _glibc_strerror_r.o \ + strspn.o strstr.o strtok.o strtok_r.o strerror.o __xpg_strerror_r.o \ + _string_syserrmsgs.o __glibc_strerror_r.o \ _string_syssigmsgs.o sys_siglist.o strsignal.o psignal.o \ __xpg_basename.o strlcat.o strlcpy.o sys_errlist.o memmem.o diff --git a/libc/string/wstring.c b/libc/string/wstring.c index ed9ebb232..6f54ae615 100644 --- a/libc/string/wstring.c +++ b/libc/string/wstring.c @@ -1299,7 +1299,7 @@ char *strerror(int errnum) { static char buf[_STRERROR_BUFSIZE]; - _susv3_strerror_r(errnum, buf, sizeof(buf)); + __xpg_strerror_r(errnum, buf, sizeof(buf)); return buf; } @@ -1308,7 +1308,7 @@ char *strerror(int errnum) /**********************************************************************/ /* SUSv3 functions. */ /**********************************************************************/ -#ifdef L__susv3_strerror_r +#ifdef L___xpg_strerror_r #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__ #if defined(__alpha__) || defined(__mips__) || defined(__sparc__) @@ -1450,7 +1450,7 @@ static const unsigned char estridx[] = { #endif -int _susv3_strerror_r(int errnum, char *strerrbuf, size_t buflen) +int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen) { register char *s; int i, retval; @@ -1528,7 +1528,7 @@ int _susv3_strerror_r(int errnum, char *strerrbuf, size_t buflen) #else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */ -int _susv3_strerror_r(int errnum, char *strerrbuf, size_t buflen) +int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen) { register char *s; int i, retval; @@ -1569,13 +1569,13 @@ int _susv3_strerror_r(int errnum, char *strerrbuf, size_t buflen) /**********************************************************************/ /* GNU extension functions. */ /**********************************************************************/ -#ifdef L__glibc_strerror_r +#ifdef L___glibc_strerror_r -weak_alias(_glibc_strerror_r,__strerror_r); +weak_alias(__glibc_strerror_r,__strerror_r); -char *_glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen) +char *__glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen) { - _susv3_strerror_r(errnum, strerrbuf, buflen); + __xpg_strerror_r(errnum, strerrbuf, buflen); return strerrbuf; } -- cgit v1.2.3