strerror_r.c (bison-3.8.1.tar.xz) | : | strerror_r.c (bison-3.8.2.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 37 | skipping to change at line 37 | |||
#include <errno.h> | #include <errno.h> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#if !HAVE_SNPRINTF | #if !HAVE_SNPRINTF | |||
# include <stdarg.h> | # include <stdarg.h> | |||
#endif | #endif | |||
#include "strerror-override.h" | #include "strerror-override.h" | |||
#if (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__) && HAVE___XPG_S TRERROR_R /* glibc >= 2.3.4, cygwin >= 1.7.9 */ | #if STRERROR_R_CHAR_P | |||
# define USE_XPG_STRERROR_R 1 | # if HAVE___XPG_STRERROR_R | |||
extern | _GL_EXTERN_C int __xpg_strerror_r (int errnum, char *buf, size_t buflen); | |||
#ifdef __cplusplus | # endif | |||
"C" | ||||
#endif | ||||
int __xpg_strerror_r (int errnum, char *buf, size_t buflen); | ||||
#elif HAVE_DECL_STRERROR_R && !(__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__) | #elif HAVE_DECL_STRERROR_R | |||
/* The system's strerror_r function is OK, except that its third argument | /* The system's strerror_r function's API is OK, except that its third argument | |||
is 'int', not 'size_t', or its return type is wrong. */ | is 'int', not 'size_t', or its return type is wrong. */ | |||
# include <limits.h> | # include <limits.h> | |||
# define USE_SYSTEM_STRERROR_R 1 | #else | |||
#else /* (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__ ? !HAVE___X | ||||
PG_STRERROR_R : !HAVE_DECL_STRERROR_R) */ | ||||
/* Use the system's strerror(). Exclude glibc and cygwin because the | /* Use the system's strerror(). Exclude glibc and cygwin because the | |||
system strerror_r has the wrong return type, and cygwin 1.7.9 | system strerror_r has the wrong return type, and cygwin 1.7.9 | |||
strerror_r clobbers strerror. */ | strerror_r clobbers strerror. */ | |||
# undef strerror | # undef strerror | |||
# define USE_SYSTEM_STRERROR 1 | ||||
# if defined __NetBSD__ || defined __hpux || (defined _WIN32 && !defined __CYGWI N__) || defined __sgi || (defined __sun && !defined _LP64) || defined __CYGWIN__ | # if defined __NetBSD__ || defined __hpux || (defined _WIN32 && !defined __CYGWI N__) || defined __sgi || (defined __sun && !defined _LP64) || defined __CYGWIN__ | |||
/* No locking needed. */ | /* No locking needed. */ | |||
/* Get catgets internationalization functions. */ | /* Get catgets internationalization functions. */ | |||
# if HAVE_CATGETS | # if HAVE_CATGETS | |||
# include <nl_types.h> | # include <nl_types.h> | |||
# endif | # endif | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
skipping to change at line 168 | skipping to change at line 161 | |||
char const *msg = strerror_override (errnum); | char const *msg = strerror_override (errnum); | |||
if (msg) | if (msg) | |||
return safe_copy (buf, buflen, msg); | return safe_copy (buf, buflen, msg); | |||
} | } | |||
{ | { | |||
int ret; | int ret; | |||
int saved_errno = errno; | int saved_errno = errno; | |||
#if USE_XPG_STRERROR_R | #if STRERROR_R_CHAR_P | |||
{ | { | |||
ret = 0; | ||||
# if HAVE___XPG_STRERROR_R | ||||
ret = __xpg_strerror_r (errnum, buf, buflen); | ret = __xpg_strerror_r (errnum, buf, buflen); | |||
if (ret < 0) | if (ret < 0) | |||
ret = errno; | ret = errno; | |||
# endif | ||||
if (!*buf) | if (!*buf) | |||
{ | { | |||
/* glibc 2.13 would not touch buf on err, so we have to fall | /* glibc 2.13 would not touch buf on err, so we have to fall | |||
back to GNU strerror_r which always returns a thread-safe | back to GNU strerror_r which always returns a thread-safe | |||
untruncated string to (partially) copy into our buf. */ | untruncated string to (partially) copy into our buf. */ | |||
safe_copy (buf, buflen, strerror_r (errnum, buf, buflen)); | char *errstring = strerror_r (errnum, buf, buflen); | |||
ret = errstring ? safe_copy (buf, buflen, errstring) : errno; | ||||
} | } | |||
} | } | |||
#elif USE_SYSTEM_STRERROR_R | #elif HAVE_DECL_STRERROR_R | |||
if (buflen > INT_MAX) | if (buflen > INT_MAX) | |||
buflen = INT_MAX; | buflen = INT_MAX; | |||
# ifdef __hpux | # ifdef __hpux | |||
/* On HP-UX 11.31, strerror_r always fails when buflen < 80; it | /* On HP-UX 11.31, strerror_r always fails when buflen < 80; it | |||
also fails to change buf on EINVAL. */ | also fails to change buf on EINVAL. */ | |||
{ | { | |||
char stackbuf[80]; | char stackbuf[80]; | |||
skipping to change at line 247 | skipping to change at line 246 | |||
{ | { | |||
char stackbuf[STACKBUF_LEN]; | char stackbuf[STACKBUF_LEN]; | |||
/* STACKBUF_LEN should have been large enough. */ | /* STACKBUF_LEN should have been large enough. */ | |||
if (strerror_r (errnum, stackbuf, sizeof stackbuf) == ERANGE) | if (strerror_r (errnum, stackbuf, sizeof stackbuf) == ERANGE) | |||
abort (); | abort (); | |||
safe_copy (buf, buflen, stackbuf); | safe_copy (buf, buflen, stackbuf); | |||
} | } | |||
# endif | # endif | |||
#else /* USE_SYSTEM_STRERROR */ | #else /* strerror_r is not declared. */ | |||
/* Try to do what strerror (errnum) does, but without clobbering the | /* Try to do what strerror (errnum) does, but without clobbering the | |||
buffer used by strerror(). */ | buffer used by strerror(). */ | |||
# if defined __NetBSD__ || defined __hpux || (defined _WIN32 && !defined __CYGWI N__) || defined __CYGWIN__ /* NetBSD, HP-UX, native Windows, Cygwin */ | # if defined __NetBSD__ || defined __hpux || (defined _WIN32 && !defined __CYGWI N__) || defined __CYGWIN__ /* NetBSD, HP-UX, native Windows, Cygwin */ | |||
/* NetBSD: sys_nerr, sys_errlist are declared through _NETBSD_SOURCE | /* NetBSD: sys_nerr, sys_errlist are declared through _NETBSD_SOURCE | |||
and <errno.h> above. | and <errno.h> above. | |||
HP-UX: sys_nerr, sys_errlist are declared explicitly above. | HP-UX: sys_nerr, sys_errlist are declared explicitly above. | |||
native Windows: sys_nerr, sys_errlist are declared in <stdlib.h>. | native Windows: sys_nerr, sys_errlist are declared in <stdlib.h>. | |||
End of changes. 12 change blocks. | ||||
19 lines changed or deleted | 17 lines changed or added |