>From f57bc6d11afae19deb915709bb9a2de66bcdeeac Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 21 Aug 2020 00:54:18 +0200 Subject: [PATCH 1/2] sigabbrev_np: New module. * lib/string.in.h (sigabbrev_np): New declaration. * lib/sigabbrev_np.c: New file. * m4/sigabbrev_np.m4: New file. * m4/string_h.m4 (gl_HEADER_STRING_H_BODY): Test whether sigabbrev_np is declared. (gl_HEADER_STRING_H_DEFAULTS): Initialize GNULIB_SIGABBREV_NP, HAVE_SIGABBREV_NP. * modules/string (Makefile.am): Substitute GNULIB_SIGABBREV_NP, HAVE_SIGABBREV_NP. * modules/sigabbrev_np: New file. * tests/test-string-c++.cc: Verify the signature of sigabbrev_np. * doc/glibc-functions/sigabbrev_np.texi: Mention the new module. --- ChangeLog | 16 ++ doc/glibc-functions/sigabbrev_np.texi | 8 +- lib/sigabbrev_np.c | 265 ++++++++++++++++++++++++++++++++++ lib/string.in.h | 15 ++ m4/sigabbrev_np.m4 | 17 +++ m4/string_h.m4 | 6 +- modules/sigabbrev_np | 28 ++++ modules/string | 2 + tests/test-string-c++.cc | 4 + 9 files changed, 355 insertions(+), 6 deletions(-) create mode 100644 lib/sigabbrev_np.c create mode 100644 m4/sigabbrev_np.m4 create mode 100644 modules/sigabbrev_np diff --git a/ChangeLog b/ChangeLog index 82ee489..8e071bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2020-08-20 Bruno Haible + sigabbrev_np: New module. + * lib/string.in.h (sigabbrev_np): New declaration. + * lib/sigabbrev_np.c: New file. + * m4/sigabbrev_np.m4: New file. + * m4/string_h.m4 (gl_HEADER_STRING_H_BODY): Test whether sigabbrev_np is + declared. + (gl_HEADER_STRING_H_DEFAULTS): Initialize GNULIB_SIGABBREV_NP, + HAVE_SIGABBREV_NP. + * modules/string (Makefile.am): Substitute GNULIB_SIGABBREV_NP, + HAVE_SIGABBREV_NP. + * modules/sigabbrev_np: New file. + * tests/test-string-c++.cc: Verify the signature of sigabbrev_np. + * doc/glibc-functions/sigabbrev_np.texi: Mention the new module. + +2020-08-20 Bruno Haible + stdalign tests: Skip test with AIX xlclang. * tests/test-stdalign.c (main): Skip alignas tests with AIX xlclang. diff --git a/doc/glibc-functions/sigabbrev_np.texi b/doc/glibc-functions/sigabbrev_np.texi index 2376dac..90a4c06 100644 --- a/doc/glibc-functions/sigabbrev_np.texi +++ b/doc/glibc-functions/sigabbrev_np.texi @@ -10,15 +10,15 @@ Documentation:@* @url{https://www.gnu.org/software/libc/manual/html_node/Signal-Messages.html}. @end ifnotinfo -Gnulib module: --- +Gnulib module: sigabbrev_np Portability problems fixed by Gnulib: @itemize +@item +This function is missing on all non-glibc platforms: +glibc 2.31, Mac OS X 10.13, FreeBSD 6.4, NetBSD 9.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on all non-glibc platforms: -glibc 2.31, Mac OS X 10.13, FreeBSD 6.4, NetBSD 9.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0. @end itemize diff --git a/lib/sigabbrev_np.c b/lib/sigabbrev_np.c new file mode 100644 index 0000000..f1c45aa --- /dev/null +++ b/lib/sigabbrev_np.c @@ -0,0 +1,265 @@ +/* Abbreviated name of signals. + Copyright (C) 2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2020. */ + +#include + +/* Specification. */ +#include + +#include + +const char * +sigabbrev_np (int sig) +{ + switch (sig) + { + /* Signals specified by ISO C. */ + case SIGABRT: return "ABRT"; + case SIGFPE: return "FPE"; + case SIGILL: return "ILL"; + case SIGINT: return "INT"; + case SIGSEGV: return "SEGV"; + case SIGTERM: return "TERM"; + + /* Signals specified by POSIX. + */ + #if defined SIGALRM + case SIGALRM: return "ALRM"; + #endif + #if defined SIGBUS + case SIGBUS: return "BUS"; + #endif + #if defined SIGCHLD + case SIGCHLD: return "CHLD"; + #endif + #if defined SIGCONT + case SIGCONT: return "CONT"; + #endif + #if defined SIGHUP + case SIGHUP: return "HUP"; + #endif + #if defined SIGKILL + case SIGKILL: return "KILL"; + #endif + #if defined SIGPIPE + case SIGPIPE: return "PIPE"; + #endif + #if defined SIGQUIT + case SIGQUIT: return "QUIT"; + #endif + #if defined SIGSTOP + case SIGSTOP: return "STOP"; + #endif + #if defined SIGTSTP + case SIGTSTP: return "TSTP"; + #endif + #if defined SIGTTIN + case SIGTTIN: return "TTIN"; + #endif + #if defined SIGTTOU + case SIGTTOU: return "TTOU"; + #endif + #if defined SIGUSR1 + case SIGUSR1: return "USR1"; + #endif + #if defined SIGUSR2 + case SIGUSR2: return "USR2"; + #endif + #if defined SIGPOLL + case SIGPOLL: return "POLL"; + #endif + #if defined SIGPROF + case SIGPROF: return "PROF"; + #endif + #if defined SIGSYS + case SIGSYS: return "SYS"; + #endif + #if defined SIGTRAP + case SIGTRAP: return "TRAP"; + #endif + #if defined SIGURG + case SIGURG: return "URG"; + #endif + #if defined SIGVTALRM + case SIGVTALRM: return "VTALRM"; + #endif + #if defined SIGXCPU + case SIGXCPU: return "XCPU"; + #endif + #if defined SIGXFSZ + case SIGXFSZ: return "XFSZ"; + #endif + + /* Other signals on other systems. */ + /* native Windows */ + #if defined SIGBREAK + case SIGBREAK: return "BREAK"; + #endif + /* IRIX */ + #if defined SIGCKPT + case SIGCKPT: return "CKPT"; + #endif + /* Linux, IRIX, Cygwin */ + #if defined SIGCLD && SIGCLD != SIGCHLD + case SIGCLD: return "CLD"; + #endif + /* AIX */ + #if defined SIGCPUFAIL + case SIGCPUFAIL: return "CPUFAIL"; + #endif + /* AIX */ + #if defined SIGDANGER + case SIGDANGER: return "DANGER"; + #endif + /* Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin, mingw */ + #if defined SIGEMT + case SIGEMT: return "EMT"; + #endif + /* Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix */ + #if defined SIGINFO + case SIGINFO: return "INFO"; + #endif + /* Linux, Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin */ + #if defined SIGIO && SIGIO != SIGPOLL + case SIGIO: return "IO"; + #endif + /* Linux, IRIX, Cygwin, mingw */ + #if defined SIGIOT && SIGIOT != SIGABRT + case SIGIOT: return "IOT"; + #endif + /* AIX */ + #if defined SIGKAP + case SIGKAP: return "KAP"; + #endif + /* Haiku */ + #if defined SIGKILLTHR + case SIGKILLTHR: return "KILLTHR"; + #endif + /* Minix */ + #if defined SIGKMEM + case SIGKMEM: return "KMEM"; + #endif + /* Minix */ + #if defined SIGKMESS + case SIGKMESS: return "KMESS"; + #endif + /* Minix */ + #if defined SIGKSIG + case SIGKSIG: return "KSIG"; + #endif + /* Minix */ + #if defined SIGKSIGSM + case SIGKSIGSM: return "KSIGSM"; + #endif + /* FreeBSD */ + #if defined SIGLIBRT + case SIGLIBRT: return "LIBRT"; + #endif + /* Cygwin */ + #if defined SIGLOST && SIGLOST != SIGABRT && SIGLOST != SIGPWR + case SIGLOST: return "LOST"; + #endif + /* AIX */ + #if defined SIGMIGRATE + case SIGMIGRATE: return "MIGRATE"; + #endif + /* AIX */ + #if defined SIGMSG + case SIGMSG: return "MSG"; + #endif + /* AIX */ + #if defined SIGPRE + case SIGPRE: return "PRE"; + #endif + /* IRIX */ + #if defined SIGPTINTR + case SIGPTINTR: return "PTINTR"; + #endif + /* IRIX */ + #if defined SIGPTRESCHED + case SIGPTRESCHED:return "PTRESCHED"; + #endif + /* Linux, NetBSD, Minix, AIX, IRIX, Cygwin */ + #if defined SIGPWR + case SIGPWR: return "PWR"; + #endif + /* AIX */ + #if defined SIGRECONFIG + case SIGRECONFIG: return "RECONFIG"; + #endif + /* AIX */ + #if defined SIGRECOVERY + case SIGRECOVERY: return "RECOVERY"; + #endif + /* IRIX */ + #if defined SIGRESTART + case SIGRESTART: return "RESTART"; + #endif + /* AIX */ + #if defined SIGRETRACT + case SIGRETRACT: return "RETRACT"; + #endif + /* AIX */ + #if defined SIGSAK + case SIGSAK: return "SAK"; + #endif + /* Minix */ + #if defined SIGSNDELAY + case SIGSNDELAY: return "SNDELAY"; + #endif + /* AIX */ + #if defined SIGSOUND + case SIGSOUND: return "SOUND"; + #endif + /* Linux */ + #if defined SIGSTKFLT + case SIGSTKFLT: return "STKFLT"; + #endif + /* AIX */ + #if defined SIGSYSERROR + case SIGSYSERROR: return "SYSERROR"; + #endif + /* AIX */ + #if defined SIGTALRM + case SIGTALRM: return "TALRM"; + #endif + /* FreeBSD, OpenBSD */ + #if defined SIGTHR + case SIGTHR: return "THR"; + #endif + /* IRIX */ + #if defined SIGUME + case SIGUME: return "UME"; + #endif + /* AIX */ + #if defined SIGVIRT + case SIGVIRT: return "VIRT"; + #endif + /* AIX */ + #if defined SIGWAITING + case SIGWAITING: return "WAITING"; + #endif + /* Linux, Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin, Haiku */ + #if defined SIGWINCH + case SIGWINCH: return "WINCH"; + #endif + + default: + return NULL; + } +} diff --git a/lib/string.in.h b/lib/string.in.h index 4c88a37..20da813 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -1045,6 +1045,21 @@ _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - " # endif #endif +/* Return an abbreviation string for the signal number SIG. */ +#if @GNULIB_SIGABBREV_NP@ +# if ! @HAVE_SIGABBREV_NP@ +_GL_FUNCDECL_SYS (sigabbrev_np, const char *, (int sig)); +# endif +_GL_CXXALIAS_SYS (sigabbrev_np, const char *, (int sig)); +_GL_CXXALIASWARN (sigabbrev_np); +#elif defined GNULIB_POSIXCHECK +# undef sigabbrev_np +# if HAVE_RAW_DECL_SIGABBREV_NP +_GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - " + "use gnulib module sigabbrev_np for portability"); +# endif +#endif + #if @GNULIB_STRSIGNAL@ # if @REPLACE_STRSIGNAL@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/sigabbrev_np.m4 b/m4/sigabbrev_np.m4 new file mode 100644 index 0000000..1aa6b3e --- /dev/null +++ b/m4/sigabbrev_np.m4 @@ -0,0 +1,17 @@ +# sigabbrev_np.m4 serial 1 +dnl Copyright (C) 2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_SIGABBREV_NP], +[ + dnl Persuade glibc to declare sigabbrev_np(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_CHECK_FUNCS([sigabbrev_np]) + if test $ac_cv_func_sigabbrev_np = no; then + HAVE_SIGABBREV_NP=0 + fi +]) diff --git a/m4/string_h.m4 b/m4/string_h.m4 index 516b346..d519bea 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -5,7 +5,7 @@ # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 24 +# serial 25 # Written by Paul Eggert. @@ -28,7 +28,7 @@ AC_DEFUN([gl_HEADER_STRING_H_BODY], ]], [ffsl ffsll memmem mempcpy memrchr rawmemchr stpcpy stpncpy strchrnul strdup strncat strndup strnlen strpbrk strsep strcasestr strtok_r - strerror_r strsignal strverscmp]) + strerror_r sigabbrev_np strsignal strverscmp]) AC_REQUIRE([AC_C_RESTRICT]) ]) @@ -80,6 +80,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R]) GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR]) GNULIB_STRERROR_R=0; AC_SUBST([GNULIB_STRERROR_R]) + GNULIB_SIGABBREV_NP=0;AC_SUBST([GNULIB_SIGABBREV_NP]) GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL]) GNULIB_STRVERSCMP=0; AC_SUBST([GNULIB_STRVERSCMP]) HAVE_MBSLEN=0; AC_SUBST([HAVE_MBSLEN]) @@ -102,6 +103,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR]) HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) HAVE_DECL_STRERROR_R=1; AC_SUBST([HAVE_DECL_STRERROR_R]) + HAVE_SIGABBREV_NP=1; AC_SUBST([HAVE_SIGABBREV_NP]) HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR]) diff --git a/modules/sigabbrev_np b/modules/sigabbrev_np new file mode 100644 index 0000000..9f2edfd --- /dev/null +++ b/modules/sigabbrev_np @@ -0,0 +1,28 @@ +Description: +sigabbrev_np() function: abbreviated name of signals. + +Files: +lib/sigabbrev_np.c +m4/sigabbrev_np.m4 + +Depends-on: +extensions +string + +configure.ac: +gl_FUNC_SIGABBREV_NP +if test $HAVE_SIGABBREV_NP = 0; then + AC_LIBOBJ([sigabbrev_np]) +fi +gl_STRING_MODULE_INDICATOR([sigabbrev_np]) + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/string b/modules/string index bc87bc8..48e5186 100644 --- a/modules/string +++ b/modules/string @@ -66,6 +66,7 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's/@''GNULIB_STRTOK_R''@/$(GNULIB_STRTOK_R)/g' \ -e 's/@''GNULIB_STRERROR''@/$(GNULIB_STRERROR)/g' \ -e 's/@''GNULIB_STRERROR_R''@/$(GNULIB_STRERROR_R)/g' \ + -e 's/@''GNULIB_SIGABBREV_NP''@/$(GNULIB_SIGABBREV_NP)/g' \ -e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \ -e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \ < $(srcdir)/string.in.h | \ @@ -88,6 +89,7 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \ + -e 's|@''HAVE_SIGABBREV_NP''@|$(HAVE_SIGABBREV_NP)|g' \ -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ diff --git a/tests/test-string-c++.cc b/tests/test-string-c++.cc index 330e697..c6dbd1a 100644 --- a/tests/test-string-c++.cc +++ b/tests/test-string-c++.cc @@ -138,6 +138,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::strerror, char *, (int)); SIGNATURE_CHECK (GNULIB_NAMESPACE::strerror_r, int, (int, char *, size_t)); #endif +#if GNULIB_TEST_SIGABBREV_NP +SIGNATURE_CHECK (GNULIB_NAMESPACE::sigabbrev_np, const char *, (int)); +#endif + #if GNULIB_TEST_STRSIGNAL SIGNATURE_CHECK (GNULIB_NAMESPACE::strsignal, char *, (int)); #endif -- 2.7.4