]> Savannah Git Hosting - gnulib.git/commitdiff
sig2str: Align with POSIX:2024.
authorBruno Haible <bruno@clisp.org>
Fri, 9 Aug 2024 20:18:16 +0000 (22:18 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 9 Aug 2024 21:21:17 +0000 (23:21 +0200)
* lib/signal.in.h (SIG2STR_MAX): New macro.
(sig2str, str2sig): New declarations.
* lib/sig2str.h: Don't include intprops.h.
(SIG2STR_MAX): Remove macro.
(sig2str, str2sig): Remove declarations.
* lib/sig2str.c: Include <signal.h> as the specification header.
* m4/signal_h.m4 (gl_SIGNAL_H): Test whether sig2str, str2sig are
declared.
(gl_SIGNAL_H_REQUIRE_DEFAULTS): Initialize GNULIB_SIG2STR.
(gl_SIGNAL_H_DEFAULTS): Initialize HAVE_SIG2STR, HAVE_STR2SIG.
* m4/sig2str.m4 (gl_FUNC_SIG2STR): Require gl_SIGNAL_H_DEFAULTS. Check
also for str2sig. Set HAVE_SIG2STR, HAVE_STR2SIG.
* modules/signal-h (Makefile.am): Substitute GNULIB_SIG2STR,
HAVE_SIG2STR, HAVE_STR2SIG.
* modules/sig2str (Depends-on): Add signal-h. Remove intprops.
(configure.ac): Test HAVE_SIG2STR, HAVE_STR2SIG. Invoke
gl_SIGNAL_MODULE_INDICATOR.
(Include): Add <signal.h>.
* doc/posix-functions/sig2str.texi: Mention as implemented through the
sig2str module.
* doc/posix-functions/str2sig.texi: Likewise.

ChangeLog
doc/posix-functions/sig2str.texi
doc/posix-functions/str2sig.texi
lib/sig2str.c
lib/sig2str.h
lib/signal.in.h
m4/sig2str.m4
m4/signal_h.m4
modules/sig2str
modules/signal-h

index e82dd02834e0295b43a4f8d91c781528b38f0136..7c9f9bce7628d6fb4e5328cc27dc61779924e426 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2024-08-09  Bruno Haible  <bruno@clisp.org>
+
+       sig2str: Align with POSIX:2024.
+       * lib/signal.in.h (SIG2STR_MAX): New macro.
+       (sig2str, str2sig): New declarations.
+       * lib/sig2str.h: Don't include intprops.h.
+       (SIG2STR_MAX): Remove macro.
+       (sig2str, str2sig): Remove declarations.
+       * lib/sig2str.c: Include <signal.h> as the specification header.
+       * m4/signal_h.m4 (gl_SIGNAL_H): Test whether sig2str, str2sig are
+       declared.
+       (gl_SIGNAL_H_REQUIRE_DEFAULTS): Initialize GNULIB_SIG2STR.
+       (gl_SIGNAL_H_DEFAULTS): Initialize HAVE_SIG2STR, HAVE_STR2SIG.
+       * m4/sig2str.m4 (gl_FUNC_SIG2STR): Require gl_SIGNAL_H_DEFAULTS. Check
+       also for str2sig. Set HAVE_SIG2STR, HAVE_STR2SIG.
+       * modules/signal-h (Makefile.am): Substitute GNULIB_SIG2STR,
+       HAVE_SIG2STR, HAVE_STR2SIG.
+       * modules/sig2str (Depends-on): Add signal-h. Remove intprops.
+       (configure.ac): Test HAVE_SIG2STR, HAVE_STR2SIG. Invoke
+       gl_SIGNAL_MODULE_INDICATOR.
+       (Include): Add <signal.h>.
+       * doc/posix-functions/sig2str.texi: Mention as implemented through the
+       sig2str module.
+       * doc/posix-functions/str2sig.texi: Likewise.
+
 2024-08-09  Paul Eggert  <eggert@cs.ucla.edu>
 
        test-utime: port to noatime file systems
index 80a177a0507ca59c1eb9ab913f7417f7445556b6..f874d9c875600097a8096a4b473cf6520fc1f14f 100644 (file)
@@ -4,18 +4,15 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/sig2str.html}
 
-Gnulib module: ---
+Gnulib module: sig2str
 
 Portability problems fixed by Gnulib:
 @itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 This function is missing on many platforms:
 glibc 2.40, macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.3.0, AIX 7.3.1, HP-UX 11.31, Cygwin 3.2.x, mingw, MSVC 14, Android 9.0.
 @end itemize
 
-Note: Gnulib has a module @code{sig2str} that implements this function,
-but declares it in a different header file.
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
index 706d2cd0c7803bafca5055359759af7153d46f48..f76b4e331d45e2d2e96c8f79c3744c95d17f4fe7 100644 (file)
@@ -4,18 +4,15 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/str2sig.html}
 
-Gnulib module: ---
+Gnulib module: sig2str
 
 Portability problems fixed by Gnulib:
 @itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 This function is missing on many platforms:
 glibc 2.40, macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, Minix 3.3.0, AIX 7.3.1, HP-UX 11.31, Cygwin 3.2.x, mingw, MSVC 14, Android 9.0.
 @end itemize
 
-Note: Gnulib has a module @code{sig2str} that implements this function,
-but declares it in a different header file.
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
index c6b91e384980d76b34f474bd2367a7698bf98d89..2dad2cd5a3ce92f5926f898e6b1793b6bce3b825 100644 (file)
 
 #include <config.h>
 
-#include <limits.h>
+/* Specification.  */
 #include <signal.h>
+
+#include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
index 391da4b1d1ce1967ec20d7fef5d006e154ba5bc3..1abdb140e5ae47504fa74a0eb4d4dc1f22d3472f 100644 (file)
 
 #include <signal.h>
 
-/* Don't override system declarations of SIG2STR_MAX, sig2str, str2sig.  */
-#ifndef SIG2STR_MAX
-
-# include "intprops.h"
-
-/* Size of a buffer needed to hold a signal name like "HUP".  */
-# define SIG2STR_MAX (sizeof "SIGRTMAX" + INT_STRLEN_BOUND (int) - 1)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int sig2str (int, char *);
-int str2sig (char const *, int *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
 /* An upper bound on signal numbers allowed by the system.  */
 
 #if defined _sys_nsig
index 7ea0242db3bc141e62177c647eaa9444b3d543c7..a0effa21ba12c6adea92e41df1e745c9820f92aa 100644 (file)
@@ -139,6 +139,47 @@ typedef void (*sighandler_t) (int);
 #endif
 
 
+/* Maximum size of a signal name returned by sig2str(), including the
+   terminating NUL byte.  */
+#ifndef SIG2STR_MAX
+/* The longest one: "RTMAX", then "+" or "-", then up to 10 digits, then NUL.
+   Add + 2 as a reserve for the future.  */
+# define SIG2STR_MAX (5 + 1 + 10 + 1 + 2)
+#endif
+
+#if @GNULIB_SIG2STR@
+# if !@HAVE_SIG2STR@
+_GL_FUNCDECL_SYS (sig2str, int, (int signo, char *str));
+# endif
+_GL_CXXALIAS_SYS (sig2str, int, (int signo, char *str));
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (sig2str);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef sig2str
+# if HAVE_RAW_DECL_SIG2STR
+_GL_WARN_ON_USE (sig2str, "sig2str is not portable - "
+                 "use gnulib module sig2str for portability");
+# endif
+#endif
+
+#if @GNULIB_SIG2STR@
+# if !@HAVE_STR2SIG@
+_GL_FUNCDECL_SYS (str2sig, int, (char const *str, int *signo_p));
+# endif
+_GL_CXXALIAS_SYS (str2sig, int, (char const *str, int *signo_p));
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (str2sig);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef str2sig
+# if HAVE_RAW_DECL_STR2SIG
+_GL_WARN_ON_USE (str2sig, "str2sig is not portable - "
+                 "use gnulib module sig2str for portability");
+# endif
+#endif
+
+
 #if @GNULIB_PTHREAD_SIGMASK@
 # if @REPLACE_PTHREAD_SIGMASK@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
index 096d0253fcb5fac106407e73569c877baae629d5..acef58a6a40ce712a204d2aed90f334bcd4130a1 100644 (file)
@@ -1,5 +1,5 @@
 # sig2str.m4
-# serial 7
+# serial 8
 dnl Copyright (C) 2002, 2005-2006, 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,7 +7,14 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_SIG2STR],
 [
-  AC_CHECK_FUNCS([sig2str])
+  AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
+  AC_CHECK_FUNCS([sig2str str2sig])
+  if test $ac_cv_func_sig2str = no; then
+    HAVE_SIG2STR=0
+  fi
+  if test $ac_cv_func_str2sig = no; then
+    HAVE_STR2SIG=0
+  fi
 ])
 
 # Prerequisites of lib/sig2str.c.
index 65afa2a1dee37858b49cc6b46e22936d0a1363ac..7a7d2b3c526d8df1e6a02f41064aa4a742f298af 100644 (file)
@@ -1,5 +1,5 @@
 # signal_h.m4
-# serial 22
+# serial 23
 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -32,7 +32,8 @@ AC_DEFUN_ONCE([gl_SIGNAL_H],
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[#include <signal.h>
-    ]], [pthread_sigmask sigaction
+    ]], [sig2str str2sig
+    pthread_sigmask sigaction
     sigaddset sigdelset sigemptyset sigfillset sigismember
     sigpending sigprocmask])
 
@@ -74,6 +75,7 @@ AC_DEFUN([gl_SIGNAL_H_REQUIRE_DEFAULTS],
   m4_defun(GL_MODULE_INDICATOR_PREFIX[_SIGNAL_H_MODULE_INDICATOR_DEFAULTS], [
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_SIGMASK])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RAISE])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIG2STR])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGNAL_H_SIGPIPE])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGPROCMASK])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGACTION])
@@ -88,9 +90,11 @@ AC_DEFUN([gl_SIGNAL_H_DEFAULTS],
   HAVE_POSIX_SIGNALBLOCKING=1; AC_SUBST([HAVE_POSIX_SIGNALBLOCKING])
   HAVE_PTHREAD_SIGMASK=1;      AC_SUBST([HAVE_PTHREAD_SIGMASK])
   HAVE_RAISE=1;                AC_SUBST([HAVE_RAISE])
+  HAVE_SIG2STR=1;              AC_SUBST([HAVE_SIG2STR])
   HAVE_SIGSET_T=1;             AC_SUBST([HAVE_SIGSET_T])
   HAVE_SIGINFO_T=1;            AC_SUBST([HAVE_SIGINFO_T])
   HAVE_SIGACTION=1;            AC_SUBST([HAVE_SIGACTION])
+  HAVE_STR2SIG=1;              AC_SUBST([HAVE_STR2SIG])
   HAVE_STRUCT_SIGACTION_SA_SIGACTION=1;
                                AC_SUBST([HAVE_STRUCT_SIGACTION_SA_SIGACTION])
   HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=1;
index cb26add2d08bb54e21061a2bda132115e494e5fe..8055a58ff1ce8ca4ed6db3dc89c1f4a4a06ade80 100644 (file)
@@ -7,14 +7,16 @@ lib/sig2str.c
 m4/sig2str.m4
 
 Depends-on:
-intprops
+signal-h
 
 configure.ac:
 gl_FUNC_SIG2STR
-gl_CONDITIONAL([GL_COND_OBJ_SIG2STR], [test $ac_cv_func_sig2str = no])
+gl_CONDITIONAL([GL_COND_OBJ_SIG2STR],
+               [test $HAVE_SIG2STR = 0 || test $HAVE_STR2SIG = 0])
 AM_COND_IF([GL_COND_OBJ_SIG2STR], [
   gl_PREREQ_SIG2STR
 ])
+gl_SIGNAL_MODULE_INDICATOR([sig2str])
 
 Makefile.am:
 if GL_COND_OBJ_SIG2STR
@@ -22,7 +24,8 @@ lib_SOURCES += sig2str.c
 endif
 
 Include:
-"sig2str.h"
+<signal.h>
+"sig2str.h" /* for SIGNUM_BOUND */
 
 License:
 GPL
index be4cf1991b3600d797dec43c073b53a579e1183f..15d8adee72279331ad377fcd8bc9821390df2817 100644 (file)
@@ -34,15 +34,18 @@ signal.h: signal.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''NEXT_SIGNAL_H''@|$(NEXT_SIGNAL_H)|g' \
              -e 's/@''GNULIB_PTHREAD_SIGMASK''@/$(GNULIB_PTHREAD_SIGMASK)/g' \
              -e 's/@''GNULIB_RAISE''@/$(GNULIB_RAISE)/g' \
+             -e 's/@''GNULIB_SIG2STR''@/$(GNULIB_SIG2STR)/g' \
              -e 's/@''GNULIB_SIGNAL_H_SIGPIPE''@/$(GNULIB_SIGNAL_H_SIGPIPE)/g' \
              -e 's/@''GNULIB_SIGPROCMASK''@/$(GNULIB_SIGPROCMASK)/g' \
              -e 's/@''GNULIB_SIGACTION''@/$(GNULIB_SIGACTION)/g' \
              -e 's|@''HAVE_POSIX_SIGNALBLOCKING''@|$(HAVE_POSIX_SIGNALBLOCKING)|g' \
              -e 's|@''HAVE_PTHREAD_SIGMASK''@|$(HAVE_PTHREAD_SIGMASK)|g' \
              -e 's|@''HAVE_RAISE''@|$(HAVE_RAISE)|g' \
+             -e 's|@''HAVE_SIG2STR''@|$(HAVE_SIG2STR)|g' \
              -e 's|@''HAVE_SIGSET_T''@|$(HAVE_SIGSET_T)|g' \
              -e 's|@''HAVE_SIGINFO_T''@|$(HAVE_SIGINFO_T)|g' \
              -e 's|@''HAVE_SIGACTION''@|$(HAVE_SIGACTION)|g' \
+             -e 's|@''HAVE_STR2SIG''@|$(HAVE_STR2SIG)|g' \
              -e 's|@''HAVE_STRUCT_SIGACTION_SA_SIGACTION''@|$(HAVE_STRUCT_SIGACTION_SA_SIGACTION)|g' \
              -e 's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \
              -e 's|@''HAVE_SIGHANDLER_T''@|$(HAVE_SIGHANDLER_T)|g' \