diff options
Diffstat (limited to 'tests/strerror_r.c')
-rw-r--r-- | tests/strerror_r.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/tests/strerror_r.c b/tests/strerror_r.c index 87fc1142..1e6974e3 100644 --- a/tests/strerror_r.c +++ b/tests/strerror_r.c @@ -1,6 +1,6 @@ /* strerror_r.c --- POSIX compatible system error routine - Copyright (C) 2010-2024 Free Software Foundation, Inc. + Copyright (C) 2010-2025 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -54,7 +54,7 @@ _GL_EXTERN_C int __xpg_strerror_r (int errnum, char *buf, size_t buflen); strerror_r clobbers strerror. */ # undef strerror -# if defined __NetBSD__ || defined __hpux || (defined _WIN32 && !defined __CYGWIN__) || defined __sgi || (defined __sun && !defined _LP64) || defined __CYGWIN__ +# if defined __NetBSD__ || defined __hpux || (defined _WIN32 && !defined __CYGWIN__) || (defined __sun && !defined _LP64) || defined __CYGWIN__ /* No locking needed. */ @@ -67,9 +67,8 @@ _GL_EXTERN_C int __xpg_strerror_r (int errnum, char *buf, size_t buflen); extern "C" { #endif -/* Get sys_nerr, sys_errlist on HP-UX (otherwise only declared in C++ mode). - Get sys_nerr, sys_errlist on IRIX (otherwise only declared with _SGIAPI). */ -# if defined __hpux || defined __sgi +/* Get sys_nerr, sys_errlist on HP-UX (otherwise only declared in C++ mode). */ +# if defined __hpux extern int sys_nerr; extern char *sys_errlist[]; # endif @@ -294,7 +293,7 @@ strerror_r (int errnum, char *buf, size_t buflen) else ret = EINVAL; -# elif defined __sgi || (defined __sun && !defined _LP64) /* IRIX, Solaris <= 9 32-bit */ +# elif defined __sun && !defined _LP64 /* Solaris <= 9 32-bit */ /* For a valid error number, the system's strerror() function returns a pointer to a not copied string, not to a buffer. */ @@ -317,10 +316,9 @@ strerror_r (int errnum, char *buf, size_t buflen) { char *errmsg = strerror (errnum); - /* For invalid error numbers, strerror() on - - IRIX 6.5 returns NULL, - - HP-UX 11 returns an empty string. */ - if (errmsg == NULL || *errmsg == '\0') + /* For invalid error numbers, strerror() on HP-UX 11 returns an empty + string. */ + if (*errmsg == '\0') ret = EINVAL; else ret = safe_copy (buf, buflen, errmsg); @@ -443,12 +441,20 @@ strerror_r (int errnum, char *buf, size_t buflen) if (ret == EINVAL && !*buf) { + /* gcc 14 produces a + "warning: 'Unknown error ' directive output truncated + writing 14 bytes into a region of size 2" + Thanks for the warning, but here the truncation is intentional. */ +#if _GL_GNUC_PREREQ (7, 1) +# pragma GCC diagnostic ignored "-Wformat-truncation" +#endif #if defined __HAIKU__ /* For consistency with perror(). */ snprintf (buf, buflen, "Unknown Application Error (%d)", errnum); #else snprintf (buf, buflen, "Unknown error %d", errnum); #endif + buf[buflen - 1] = '\0'; } errno = saved_errno; |