]> Savannah Git Hosting - gnulib.git/commitdiff
sigabbrev_np: New module.
authorBruno Haible <bruno@clisp.org>
Thu, 20 Aug 2020 22:54:18 +0000 (00:54 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 20 Aug 2020 23:18:07 +0000 (01:18 +0200)
* 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
doc/glibc-functions/sigabbrev_np.texi
lib/sigabbrev_np.c [new file with mode: 0644]
lib/string.in.h
m4/sigabbrev_np.m4 [new file with mode: 0644]
m4/string_h.m4
modules/sigabbrev_np [new file with mode: 0644]
modules/string
tests/test-string-c++.cc

index 82ee4897d4ccfc0f720ad8dcb944ede78de5742e..8e071bf8dd117dfb60a79e56d437d0b398c99619 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2020-08-20  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        stdalign tests: Skip test with AIX xlclang.
index 2376dac436229b4c6659e133c9425ed4ea3dd4a7..90a4c06ed422e97bb0b787d9d1e378acf316c4b7 100644 (file)
@@ -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 (file)
index 0000000..f1c45aa
--- /dev/null
@@ -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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <signal.h>
+
+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.
+       <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html>  */
+    #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;
+    }
+}
index 4c88a373f82c3852fd55e5871fb11f5a03ce8895..20da81386609da759559edba1c9f49b340ecdbf2 100644 (file)
@@ -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 (file)
index 0000000..1aa6b3e
--- /dev/null
@@ -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 <string.h> 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
+])
index 516b346b311c178f78c480639b33ef51b8d0e843..d519beaa59174efb2b0cd996fd3ee35d7d8a8732 100644 (file)
@@ -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 (file)
index 0000000..9f2edfd
--- /dev/null
@@ -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:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
index bc87bc8818ecc8bb99d87c382aecf82fda73bd1a..48e5186cd847ca32be8c823c15d441fd93a995bb 100644 (file)
@@ -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' \
index 330e697278cfa1e75174ef184af4ed00a9640f11..c6dbd1a115fab73aee156b87dbe8ca173a6a9ec4 100644 (file)
@@ -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