]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libiberty/strsignal.c
Add prange entries in gimple-range-op.cc.
[thirdparty/gcc.git] / libiberty / strsignal.c
index 45b052826dfdf7be13b2fa4e1c3376e2240e1e58..36b41f17e1232e171c1c1c8e2266fe1d0f549b9b 100644 (file)
@@ -2,53 +2,53 @@
    Written by Fred Fish.  fnf@cygnus.com
    This file is in the public domain.  */
 
+#include "config.h"
 #include "ansidecl.h"
 #include "libiberty.h"
 
-#include "config.h"
-
 /* We need to declare sys_siglist, because even if the system provides
    it we can't assume that it is declared in <signal.h> (for example,
    SunOS provides sys_siglist, but it does not declare it in any
-   header file).  fHowever, we can't declare sys_siglist portably,
+   header file).  However, we can't declare sys_siglist portably,
    because on some systems it is declared with const and on some
    systems it is declared without const.  If we were using autoconf,
    we could work out the right declaration.  Until, then we just
    ignore any declaration in the system header files, and always
    declare it ourselves.  With luck, this will always work.  */
 #define sys_siglist no_such_symbol
+#define sys_nsig sys_nsig__no_such_symbol
 
 #include <stdio.h>
 #include <signal.h>
 
 /*  Routines imported from standard C runtime libraries. */
 
-#ifdef __STDC__
-#include <stddef.h>
-extern void *malloc (size_t size);                             /* 4.10.3.3 */
-extern void *memset (void *s, int c, size_t n);                        /* 4.11.6.1 */
-#else  /* !__STDC__ */
-extern char *malloc ();                /* Standard memory allocater */
-extern char *memset ();
-#endif /* __STDC__ */
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#else
+extern void *malloc ();
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+extern void *memset ();
+#endif
 
 /* Undefine the macro we used to hide the definition of sys_siglist
    found in the system header files.  */
 #undef sys_siglist
+#undef sys_nsig
 
 #ifndef NULL
-#  ifdef __STDC__
-#    define NULL (void *) 0
-#  else
-#    define NULL 0
-#  endif
+#  define NULL (void *) 0
 #endif
 
 #ifndef MAX
 #  define MAX(a,b) ((a) > (b) ? (a) : (b))
 #endif
 
-static void init_signal_tables PARAMS ((void));
+static void init_signal_tables (void);
 
 /* Translation table for signal values.
 
@@ -62,14 +62,14 @@ static void init_signal_tables PARAMS ((void));
 
 struct signal_info
 {
-  int value;           /* The numeric value from <signal.h> */
-  const char *name;    /* The equivalent symbolic value */
-#ifdef NEED_sys_siglist
-  const char *msg;     /* Short message about this value */
+  const int value;             /* The numeric value from <signal.h> */
+  const char *const name;      /* The equivalent symbolic value */
+#ifndef HAVE_SYS_SIGLIST
+  const char *const msg;       /* Short message about this value */
 #endif
 };
 
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
 #   define ENTRY(value, name, msg)     {value, name, msg}
 #else
 #   define ENTRY(value, name, msg)     {value, name}
@@ -236,7 +236,7 @@ static int num_signal_names = 0;
    same name, it differs from other implementations in that it is dynamically
    initialized rather than statically initialized. */
 
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
 
 static int sys_nsig;
 static const char **sys_siglist;
@@ -247,7 +247,7 @@ static const char **sys_siglist;
 static int sys_nsig = NSIG;
 #else
 #ifdef _NSIG
-static int sys_nsig = NSIG;
+static int sys_nsig = _NSIG;
 #endif
 #endif
 extern const char * const sys_siglist[];
@@ -284,7 +284,7 @@ BUGS
 */
 
 static void
-init_signal_tables ()
+init_signal_tables (void)
 {
   const struct signal_info *eip;
   int nbytes;
@@ -319,7 +319,7 @@ init_signal_tables ()
        }
     }
 
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
 
   /* Now attempt to allocate the sys_siglist table, zero it out, and then
      initialize it from the statically initialized signal_table. */
@@ -345,33 +345,27 @@ init_signal_tables ()
 
 /*
 
-NAME
+@deftypefn Extension int signo_max (void)
 
-       signo_max -- return the max signo value
+Returns the maximum signal value for which a corresponding symbolic
+name or message is available.  Note that in the case where we use the
+@code{sys_siglist} supplied by the system, it is possible for there to
+be more symbolic names than messages, or vice versa.  In fact, the
+manual page for @code{psignal(3b)} explicitly warns that one should
+check the size of the table (@code{NSIG}) before indexing it, since
+new signal codes may be added to the system before they are added to
+the table.  Thus @code{NSIG} might be smaller than value implied by
+the largest signo value defined in @code{<signal.h>}.
 
-SYNOPSIS
+We return the maximum value that can be used to obtain a meaningful
+symbolic name or message.
 
-       int signo_max ();
-
-DESCRIPTION
-
-       Returns the maximum signo value for which a corresponding symbolic
-       name or message is available.  Note that in the case where
-       we use the sys_siglist supplied by the system, it is possible for
-       there to be more symbolic names than messages, or vice versa.
-       In fact, the manual page for psignal(3b) explicitly warns that one
-       should check the size of the table (NSIG) before indexing it,
-       since new signal codes may be added to the system before they are
-       added to the table.  Thus NSIG might be smaller than value
-       implied by the largest signo value defined in <signal.h>.
-
-       We return the maximum value that can be used to obtain a meaningful
-       symbolic name or message.
+@end deftypefn
 
 */
 
 int
-signo_max ()
+signo_max (void)
 {
   int maxsize;
 
@@ -386,44 +380,37 @@ signo_max ()
 
 /*
 
-NAME
+@deftypefn Supplemental {const char *} strsignal (int @var{signo})
 
-       strsignal -- map a signal number to a signal message string
+Maps an signal number to an signal message string, the contents of
+which are implementation defined.  On systems which have the external
+variable @code{sys_siglist}, these strings will be the same as the
+ones used by @code{psignal()}.
 
-SYNOPSIS
+If the supplied signal number is within the valid range of indices for
+the @code{sys_siglist}, but no message is available for the particular
+signal number, then returns the string @samp{Signal @var{num}}, where
+@var{num} is the signal number.
 
-       const char *strsignal (int signo)
+If the supplied signal number is not a valid index into
+@code{sys_siglist}, returns @code{NULL}.
 
-DESCRIPTION
+The returned string is only guaranteed to be valid only until the next
+call to @code{strsignal}.
 
-       Maps an signal number to an signal message string, the contents of
-       which are implementation defined.  On systems which have the external
-       variable sys_siglist, these strings will be the same as the ones used
-       by psignal().
-
-       If the supplied signal number is within the valid range of indices
-       for the sys_siglist, but no message is available for the particular
-       signal number, then returns the string "Signal NUM", where NUM is the
-       signal number.
-
-       If the supplied signal number is not a valid index into sys_siglist,
-       returns NULL.
-
-       The returned string is only guaranteed to be valid only until the
-       next call to strsignal.
+@end deftypefn
 
 */
 
-#ifdef NEED_strsignal
+#ifndef HAVE_STRSIGNAL
 
-const char *
-strsignal (signo)
-  int signo;
+char *
+strsignal (int signo)
 {
-  const char *msg;
+  char *msg;
   static char buf[32];
 
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
 
   if (signal_names == NULL)
     {
@@ -441,52 +428,45 @@ strsignal (signo)
     {
       /* In range, but no sys_siglist or no entry at this index. */
       sprintf (buf, "Signal %d", signo);
-      msg = (const char *) buf;
+      msg = buf;
     }
   else
     {
-      /* In range, and a valid message.  Just return the message. */
-      msg = (const char *) sys_siglist[signo];
+      /* In range, and a valid message.  Just return the message.  We
+        can safely cast away const, since POSIX says the user must
+        not modify the result.  */
+      msg = (char *) sys_siglist[signo];
     }
-  
+
   return (msg);
 }
 
-#endif /* NEED_strsignal */
+#endif /* ! HAVE_STRSIGNAL */
 
 /*
 
-NAME
-
-       strsigno -- map an signal number to a symbolic name string
+@deftypefn Extension {const char*} strsigno (int @var{signo})
 
-SYNOPSIS
+Given an signal number, returns a pointer to a string containing the
+symbolic name of that signal number, as found in @code{<signal.h>}.
 
-       const char *strsigno (int signo)
+If the supplied signal number is within the valid range of indices for
+symbolic names, but no name is available for the particular signal
+number, then returns the string @samp{Signal @var{num}}, where
+@var{num} is the signal number.
 
-DESCRIPTION
+If the supplied signal number is not within the range of valid
+indices, then returns @code{NULL}.
 
-       Given an signal number, returns a pointer to a string containing
-       the symbolic name of that signal number, as found in <signal.h>.
+The contents of the location pointed to are only guaranteed to be
+valid until the next call to @code{strsigno}.
 
-       If the supplied signal number is within the valid range of indices
-       for symbolic names, but no name is available for the particular
-       signal number, then returns the string "Signal NUM", where NUM is
-       the signal number.
-
-       If the supplied signal number is not within the range of valid
-       indices, then returns NULL.
-
-BUGS
-
-       The contents of the location pointed to are only guaranteed to be
-       valid until the next call to strsigno.
+@end deftypefn
 
 */
 
 const char *
-strsigno (signo)
-  int signo;
+strsigno (int signo)
 {
   const char *name;
   static char buf[32];
@@ -519,24 +499,17 @@ strsigno (signo)
 
 /*
 
-NAME
-
-       strtosigno -- map a symbolic signal name to a numeric value
-
-SYNOPSIS
-
-       int strtosigno (char *name)
+@deftypefn Extension int strtosigno (const char *@var{name})
 
-DESCRIPTION
+Given the symbolic name of a signal, map it to a signal number.  If no
+translation is found, returns 0.
 
-       Given the symbolic name of a signal, map it to a signal number.
-       If no translation is found, returns 0.
+@end deftypefn
 
 */
 
 int
-strtosigno (name)
-     const char *name;
+strtosigno (const char *name)
 {
   int signo = 0;
 
@@ -565,27 +538,20 @@ strtosigno (name)
 
 /*
 
-NAME
-
-       psignal -- print message about signal to stderr
+@deftypefn Supplemental void psignal (int @var{signo}, char *@var{message})
 
-SYNOPSIS
+Print @var{message} to the standard error, followed by a colon,
+followed by the description of the signal specified by @var{signo},
+followed by a newline.
 
-       void psignal (unsigned signo, char *message);
-
-DESCRIPTION
+@end deftypefn
 
-       Print to the standard error the message, followed by a colon,
-       followed by the description of the signal specified by signo,
-       followed by a newline.
 */
 
-#ifdef NEED_psignal
+#ifndef HAVE_PSIGNAL
 
 void
-psignal (signo, message)
-  unsigned signo;
-  char *message;
+psignal (int signo, char *message)
 {
   if (signal_names == NULL)
     {
@@ -601,7 +567,7 @@ psignal (signo, message)
     }
 }
 
-#endif /* NEED_psignal */
+#endif /* ! HAVE_PSIGNAL */
 
 
 /* A simple little main that does nothing but print all the signal translations
@@ -612,7 +578,7 @@ psignal (signo, message)
 #include <stdio.h>
 
 int
-main ()
+main (void)
 {
   int signo;
   int maxsigno;