OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [libiberty/] [strsignal.c] - Diff between revs 107 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 107 Rev 1765
/* Extended support for using signal values.
/* Extended support for using signal values.
   Written by Fred Fish.  fnf@cygnus.com
   Written by Fred Fish.  fnf@cygnus.com
   This file is in the public domain.  */
   This file is in the public domain.  */
 
 
#include "ansidecl.h"
#include "ansidecl.h"
#include "libiberty.h"
#include "libiberty.h"
 
 
#include "config.h"
#include "config.h"
 
 
/* We need to declare sys_siglist, because even if the system provides
/* 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,
   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
   SunOS provides sys_siglist, but it does not declare it in any
   header file).  fHowever, we can't declare sys_siglist portably,
   header file).  fHowever, we can't declare sys_siglist portably,
   because on some systems it is declared with const and on some
   because on some systems it is declared with const and on some
   systems it is declared without const.  If we were using autoconf,
   systems it is declared without const.  If we were using autoconf,
   we could work out the right declaration.  Until, then we just
   we could work out the right declaration.  Until, then we just
   ignore any declaration in the system header files, and always
   ignore any declaration in the system header files, and always
   declare it ourselves.  With luck, this will always work.  */
   declare it ourselves.  With luck, this will always work.  */
#define sys_siglist no_such_symbol
#define sys_siglist no_such_symbol
 
 
#include <stdio.h>
#include <stdio.h>
#include <signal.h>
#include <signal.h>
 
 
/*  Routines imported from standard C runtime libraries. */
/*  Routines imported from standard C runtime libraries. */
 
 
#ifdef __STDC__
#ifdef __STDC__
#include <stddef.h>
#include <stddef.h>
extern void *malloc (size_t size);                              /* 4.10.3.3 */
extern void *malloc (size_t size);                              /* 4.10.3.3 */
extern void *memset (void *s, int c, size_t n);                 /* 4.11.6.1 */
extern void *memset (void *s, int c, size_t n);                 /* 4.11.6.1 */
#else   /* !__STDC__ */
#else   /* !__STDC__ */
extern char *malloc ();         /* Standard memory allocater */
extern char *malloc ();         /* Standard memory allocater */
extern char *memset ();
extern char *memset ();
#endif  /* __STDC__ */
#endif  /* __STDC__ */
 
 
/* Undefine the macro we used to hide the definition of sys_siglist
/* Undefine the macro we used to hide the definition of sys_siglist
   found in the system header files.  */
   found in the system header files.  */
#undef sys_siglist
#undef sys_siglist
 
 
#ifndef NULL
#ifndef NULL
#  ifdef __STDC__
#  ifdef __STDC__
#    define NULL (void *) 0
#    define NULL (void *) 0
#  else
#  else
#    define NULL 0
#    define NULL 0
#  endif
#  endif
#endif
#endif
 
 
#ifndef MAX
#ifndef MAX
#  define MAX(a,b) ((a) > (b) ? (a) : (b))
#  define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#endif
 
 
static void init_signal_tables PARAMS ((void));
static void init_signal_tables PARAMS ((void));
 
 
/* Translation table for signal values.
/* Translation table for signal values.
 
 
   Note that this table is generally only accessed when it is used at runtime
   Note that this table is generally only accessed when it is used at runtime
   to initialize signal name and message tables that are indexed by signal
   to initialize signal name and message tables that are indexed by signal
   value.
   value.
 
 
   Not all of these signals will exist on all systems.  This table is the only
   Not all of these signals will exist on all systems.  This table is the only
   thing that should have to be updated as new signal numbers are introduced.
   thing that should have to be updated as new signal numbers are introduced.
   It's sort of ugly, but at least its portable. */
   It's sort of ugly, but at least its portable. */
 
 
struct signal_info
struct signal_info
{
{
  int value;            /* The numeric value from <signal.h> */
  int value;            /* The numeric value from <signal.h> */
  const char *name;     /* The equivalent symbolic value */
  const char *name;     /* The equivalent symbolic value */
#ifndef HAVE_SYS_SIGLIST
#ifndef HAVE_SYS_SIGLIST
  const char *msg;      /* Short message about this value */
  const char *msg;      /* Short message about this value */
#endif
#endif
};
};
 
 
#ifndef HAVE_SYS_SIGLIST
#ifndef HAVE_SYS_SIGLIST
#   define ENTRY(value, name, msg)      {value, name, msg}
#   define ENTRY(value, name, msg)      {value, name, msg}
#else
#else
#   define ENTRY(value, name, msg)      {value, name}
#   define ENTRY(value, name, msg)      {value, name}
#endif
#endif
 
 
static const struct signal_info signal_table[] =
static const struct signal_info signal_table[] =
{
{
#if defined (SIGHUP)
#if defined (SIGHUP)
  ENTRY(SIGHUP, "SIGHUP", "Hangup"),
  ENTRY(SIGHUP, "SIGHUP", "Hangup"),
#endif
#endif
#if defined (SIGINT)
#if defined (SIGINT)
  ENTRY(SIGINT, "SIGINT", "Interrupt"),
  ENTRY(SIGINT, "SIGINT", "Interrupt"),
#endif
#endif
#if defined (SIGQUIT)
#if defined (SIGQUIT)
  ENTRY(SIGQUIT, "SIGQUIT", "Quit"),
  ENTRY(SIGQUIT, "SIGQUIT", "Quit"),
#endif
#endif
#if defined (SIGILL)
#if defined (SIGILL)
  ENTRY(SIGILL, "SIGILL", "Illegal instruction"),
  ENTRY(SIGILL, "SIGILL", "Illegal instruction"),
#endif
#endif
#if defined (SIGTRAP)
#if defined (SIGTRAP)
  ENTRY(SIGTRAP, "SIGTRAP", "Trace/breakpoint trap"),
  ENTRY(SIGTRAP, "SIGTRAP", "Trace/breakpoint trap"),
#endif
#endif
/* Put SIGIOT before SIGABRT, so that if SIGIOT==SIGABRT then SIGABRT
/* Put SIGIOT before SIGABRT, so that if SIGIOT==SIGABRT then SIGABRT
   overrides SIGIOT.  SIGABRT is in ANSI and POSIX.1, and SIGIOT isn't. */
   overrides SIGIOT.  SIGABRT is in ANSI and POSIX.1, and SIGIOT isn't. */
#if defined (SIGIOT)
#if defined (SIGIOT)
  ENTRY(SIGIOT, "SIGIOT", "IOT trap"),
  ENTRY(SIGIOT, "SIGIOT", "IOT trap"),
#endif
#endif
#if defined (SIGABRT)
#if defined (SIGABRT)
  ENTRY(SIGABRT, "SIGABRT", "Aborted"),
  ENTRY(SIGABRT, "SIGABRT", "Aborted"),
#endif
#endif
#if defined (SIGEMT)
#if defined (SIGEMT)
  ENTRY(SIGEMT, "SIGEMT", "Emulation trap"),
  ENTRY(SIGEMT, "SIGEMT", "Emulation trap"),
#endif
#endif
#if defined (SIGFPE)
#if defined (SIGFPE)
  ENTRY(SIGFPE, "SIGFPE", "Arithmetic exception"),
  ENTRY(SIGFPE, "SIGFPE", "Arithmetic exception"),
#endif
#endif
#if defined (SIGKILL)
#if defined (SIGKILL)
  ENTRY(SIGKILL, "SIGKILL", "Killed"),
  ENTRY(SIGKILL, "SIGKILL", "Killed"),
#endif
#endif
#if defined (SIGBUS)
#if defined (SIGBUS)
  ENTRY(SIGBUS, "SIGBUS", "Bus error"),
  ENTRY(SIGBUS, "SIGBUS", "Bus error"),
#endif
#endif
#if defined (SIGSEGV)
#if defined (SIGSEGV)
  ENTRY(SIGSEGV, "SIGSEGV", "Segmentation fault"),
  ENTRY(SIGSEGV, "SIGSEGV", "Segmentation fault"),
#endif
#endif
#if defined (SIGSYS)
#if defined (SIGSYS)
  ENTRY(SIGSYS, "SIGSYS", "Bad system call"),
  ENTRY(SIGSYS, "SIGSYS", "Bad system call"),
#endif
#endif
#if defined (SIGPIPE)
#if defined (SIGPIPE)
  ENTRY(SIGPIPE, "SIGPIPE", "Broken pipe"),
  ENTRY(SIGPIPE, "SIGPIPE", "Broken pipe"),
#endif
#endif
#if defined (SIGALRM)
#if defined (SIGALRM)
  ENTRY(SIGALRM, "SIGALRM", "Alarm clock"),
  ENTRY(SIGALRM, "SIGALRM", "Alarm clock"),
#endif
#endif
#if defined (SIGTERM)
#if defined (SIGTERM)
  ENTRY(SIGTERM, "SIGTERM", "Terminated"),
  ENTRY(SIGTERM, "SIGTERM", "Terminated"),
#endif
#endif
#if defined (SIGUSR1)
#if defined (SIGUSR1)
  ENTRY(SIGUSR1, "SIGUSR1", "User defined signal 1"),
  ENTRY(SIGUSR1, "SIGUSR1", "User defined signal 1"),
#endif
#endif
#if defined (SIGUSR2)
#if defined (SIGUSR2)
  ENTRY(SIGUSR2, "SIGUSR2", "User defined signal 2"),
  ENTRY(SIGUSR2, "SIGUSR2", "User defined signal 2"),
#endif
#endif
/* Put SIGCLD before SIGCHLD, so that if SIGCLD==SIGCHLD then SIGCHLD
/* Put SIGCLD before SIGCHLD, so that if SIGCLD==SIGCHLD then SIGCHLD
   overrides SIGCLD.  SIGCHLD is in POXIX.1 */
   overrides SIGCLD.  SIGCHLD is in POXIX.1 */
#if defined (SIGCLD)
#if defined (SIGCLD)
  ENTRY(SIGCLD, "SIGCLD", "Child status changed"),
  ENTRY(SIGCLD, "SIGCLD", "Child status changed"),
#endif
#endif
#if defined (SIGCHLD)
#if defined (SIGCHLD)
  ENTRY(SIGCHLD, "SIGCHLD", "Child status changed"),
  ENTRY(SIGCHLD, "SIGCHLD", "Child status changed"),
#endif
#endif
#if defined (SIGPWR)
#if defined (SIGPWR)
  ENTRY(SIGPWR, "SIGPWR", "Power fail/restart"),
  ENTRY(SIGPWR, "SIGPWR", "Power fail/restart"),
#endif
#endif
#if defined (SIGWINCH)
#if defined (SIGWINCH)
  ENTRY(SIGWINCH, "SIGWINCH", "Window size changed"),
  ENTRY(SIGWINCH, "SIGWINCH", "Window size changed"),
#endif
#endif
#if defined (SIGURG)
#if defined (SIGURG)
  ENTRY(SIGURG, "SIGURG", "Urgent I/O condition"),
  ENTRY(SIGURG, "SIGURG", "Urgent I/O condition"),
#endif
#endif
#if defined (SIGIO)
#if defined (SIGIO)
  /* "I/O pending" has also been suggested, but is misleading since the
  /* "I/O pending" has also been suggested, but is misleading since the
     signal only happens when the process has asked for it, not everytime
     signal only happens when the process has asked for it, not everytime
     I/O is pending. */
     I/O is pending. */
  ENTRY(SIGIO, "SIGIO", "I/O possible"),
  ENTRY(SIGIO, "SIGIO", "I/O possible"),
#endif
#endif
#if defined (SIGPOLL)
#if defined (SIGPOLL)
  ENTRY(SIGPOLL, "SIGPOLL", "Pollable event occurred"),
  ENTRY(SIGPOLL, "SIGPOLL", "Pollable event occurred"),
#endif
#endif
#if defined (SIGSTOP)
#if defined (SIGSTOP)
  ENTRY(SIGSTOP, "SIGSTOP", "Stopped (signal)"),
  ENTRY(SIGSTOP, "SIGSTOP", "Stopped (signal)"),
#endif
#endif
#if defined (SIGTSTP)
#if defined (SIGTSTP)
  ENTRY(SIGTSTP, "SIGTSTP", "Stopped (user)"),
  ENTRY(SIGTSTP, "SIGTSTP", "Stopped (user)"),
#endif
#endif
#if defined (SIGCONT)
#if defined (SIGCONT)
  ENTRY(SIGCONT, "SIGCONT", "Continued"),
  ENTRY(SIGCONT, "SIGCONT", "Continued"),
#endif
#endif
#if defined (SIGTTIN)
#if defined (SIGTTIN)
  ENTRY(SIGTTIN, "SIGTTIN", "Stopped (tty input)"),
  ENTRY(SIGTTIN, "SIGTTIN", "Stopped (tty input)"),
#endif
#endif
#if defined (SIGTTOU)
#if defined (SIGTTOU)
  ENTRY(SIGTTOU, "SIGTTOU", "Stopped (tty output)"),
  ENTRY(SIGTTOU, "SIGTTOU", "Stopped (tty output)"),
#endif
#endif
#if defined (SIGVTALRM)
#if defined (SIGVTALRM)
  ENTRY(SIGVTALRM, "SIGVTALRM", "Virtual timer expired"),
  ENTRY(SIGVTALRM, "SIGVTALRM", "Virtual timer expired"),
#endif
#endif
#if defined (SIGPROF)
#if defined (SIGPROF)
  ENTRY(SIGPROF, "SIGPROF", "Profiling timer expired"),
  ENTRY(SIGPROF, "SIGPROF", "Profiling timer expired"),
#endif
#endif
#if defined (SIGXCPU)
#if defined (SIGXCPU)
  ENTRY(SIGXCPU, "SIGXCPU", "CPU time limit exceeded"),
  ENTRY(SIGXCPU, "SIGXCPU", "CPU time limit exceeded"),
#endif
#endif
#if defined (SIGXFSZ)
#if defined (SIGXFSZ)
  ENTRY(SIGXFSZ, "SIGXFSZ", "File size limit exceeded"),
  ENTRY(SIGXFSZ, "SIGXFSZ", "File size limit exceeded"),
#endif
#endif
#if defined (SIGWIND)
#if defined (SIGWIND)
  ENTRY(SIGWIND, "SIGWIND", "SIGWIND"),
  ENTRY(SIGWIND, "SIGWIND", "SIGWIND"),
#endif
#endif
#if defined (SIGPHONE)
#if defined (SIGPHONE)
  ENTRY(SIGPHONE, "SIGPHONE", "SIGPHONE"),
  ENTRY(SIGPHONE, "SIGPHONE", "SIGPHONE"),
#endif
#endif
#if defined (SIGLOST)
#if defined (SIGLOST)
  ENTRY(SIGLOST, "SIGLOST", "Resource lost"),
  ENTRY(SIGLOST, "SIGLOST", "Resource lost"),
#endif
#endif
#if defined (SIGWAITING)
#if defined (SIGWAITING)
  ENTRY(SIGWAITING, "SIGWAITING", "Process's LWPs are blocked"),
  ENTRY(SIGWAITING, "SIGWAITING", "Process's LWPs are blocked"),
#endif
#endif
#if defined (SIGLWP)
#if defined (SIGLWP)
  ENTRY(SIGLWP, "SIGLWP", "Signal LWP"),
  ENTRY(SIGLWP, "SIGLWP", "Signal LWP"),
#endif
#endif
#if defined (SIGDANGER)
#if defined (SIGDANGER)
  ENTRY(SIGDANGER, "SIGDANGER", "Swap space dangerously low"),
  ENTRY(SIGDANGER, "SIGDANGER", "Swap space dangerously low"),
#endif
#endif
#if defined (SIGGRANT)
#if defined (SIGGRANT)
  ENTRY(SIGGRANT, "SIGGRANT", "Monitor mode granted"),
  ENTRY(SIGGRANT, "SIGGRANT", "Monitor mode granted"),
#endif
#endif
#if defined (SIGRETRACT)
#if defined (SIGRETRACT)
  ENTRY(SIGRETRACT, "SIGRETRACT", "Need to relinguish monitor mode"),
  ENTRY(SIGRETRACT, "SIGRETRACT", "Need to relinguish monitor mode"),
#endif
#endif
#if defined (SIGMSG)
#if defined (SIGMSG)
  ENTRY(SIGMSG, "SIGMSG", "Monitor mode data available"),
  ENTRY(SIGMSG, "SIGMSG", "Monitor mode data available"),
#endif
#endif
#if defined (SIGSOUND)
#if defined (SIGSOUND)
  ENTRY(SIGSOUND, "SIGSOUND", "Sound completed"),
  ENTRY(SIGSOUND, "SIGSOUND", "Sound completed"),
#endif
#endif
#if defined (SIGSAK)
#if defined (SIGSAK)
  ENTRY(SIGSAK, "SIGSAK", "Secure attention"),
  ENTRY(SIGSAK, "SIGSAK", "Secure attention"),
#endif
#endif
  ENTRY(0, NULL, NULL)
  ENTRY(0, NULL, NULL)
};
};
 
 
/* Translation table allocated and initialized at runtime.  Indexed by the
/* Translation table allocated and initialized at runtime.  Indexed by the
   signal value to find the equivalent symbolic value. */
   signal value to find the equivalent symbolic value. */
 
 
static const char **signal_names;
static const char **signal_names;
static int num_signal_names = 0;
static int num_signal_names = 0;
 
 
/* Translation table allocated and initialized at runtime, if it does not
/* Translation table allocated and initialized at runtime, if it does not
   already exist in the host environment.  Indexed by the signal value to find
   already exist in the host environment.  Indexed by the signal value to find
   the descriptive string.
   the descriptive string.
 
 
   We don't export it for use in other modules because even though it has the
   We don't export it for use in other modules because even though it has the
   same name, it differs from other implementations in that it is dynamically
   same name, it differs from other implementations in that it is dynamically
   initialized rather than statically initialized. */
   initialized rather than statically initialized. */
 
 
#ifndef HAVE_SYS_SIGLIST
#ifndef HAVE_SYS_SIGLIST
 
 
static int sys_nsig;
static int sys_nsig;
static const char **sys_siglist;
static const char **sys_siglist;
 
 
#else
#else
 
 
#ifdef NSIG
#ifdef NSIG
static int sys_nsig = NSIG;
static int sys_nsig = NSIG;
#else
#else
#ifdef _NSIG
#ifdef _NSIG
static int sys_nsig = _NSIG;
static int sys_nsig = _NSIG;
#endif
#endif
#endif
#endif
extern const char * const sys_siglist[];
extern const char * const sys_siglist[];
 
 
#endif
#endif
 
 
 
 
/*
/*
 
 
NAME
NAME
 
 
        init_signal_tables -- initialize the name and message tables
        init_signal_tables -- initialize the name and message tables
 
 
SYNOPSIS
SYNOPSIS
 
 
        static void init_signal_tables ();
        static void init_signal_tables ();
 
 
DESCRIPTION
DESCRIPTION
 
 
        Using the signal_table, which is initialized at compile time, generate
        Using the signal_table, which is initialized at compile time, generate
        the signal_names and the sys_siglist (if needed) tables, which are
        the signal_names and the sys_siglist (if needed) tables, which are
        indexed at runtime by a specific signal value.
        indexed at runtime by a specific signal value.
 
 
BUGS
BUGS
 
 
        The initialization of the tables may fail under low memory conditions,
        The initialization of the tables may fail under low memory conditions,
        in which case we don't do anything particularly useful, but we don't
        in which case we don't do anything particularly useful, but we don't
        bomb either.  Who knows, it might succeed at a later point if we free
        bomb either.  Who knows, it might succeed at a later point if we free
        some memory in the meantime.  In any case, the other routines know
        some memory in the meantime.  In any case, the other routines know
        how to deal with lack of a table after trying to initialize it.  This
        how to deal with lack of a table after trying to initialize it.  This
        may or may not be considered to be a bug, that we don't specifically
        may or may not be considered to be a bug, that we don't specifically
        warn about this particular failure mode.
        warn about this particular failure mode.
 
 
*/
*/
 
 
static void
static void
init_signal_tables ()
init_signal_tables ()
{
{
  const struct signal_info *eip;
  const struct signal_info *eip;
  int nbytes;
  int nbytes;
 
 
  /* If we haven't already scanned the signal_table once to find the maximum
  /* If we haven't already scanned the signal_table once to find the maximum
     signal value, then go find it now. */
     signal value, then go find it now. */
 
 
  if (num_signal_names == 0)
  if (num_signal_names == 0)
    {
    {
      for (eip = signal_table; eip -> name != NULL; eip++)
      for (eip = signal_table; eip -> name != NULL; eip++)
        {
        {
          if (eip -> value >= num_signal_names)
          if (eip -> value >= num_signal_names)
            {
            {
              num_signal_names = eip -> value + 1;
              num_signal_names = eip -> value + 1;
            }
            }
        }
        }
    }
    }
 
 
  /* Now attempt to allocate the signal_names table, zero it out, and then
  /* Now attempt to allocate the signal_names table, zero it out, and then
     initialize it from the statically initialized signal_table. */
     initialize it from the statically initialized signal_table. */
 
 
  if (signal_names == NULL)
  if (signal_names == NULL)
    {
    {
      nbytes = num_signal_names * sizeof (char *);
      nbytes = num_signal_names * sizeof (char *);
      if ((signal_names = (const char **) malloc (nbytes)) != NULL)
      if ((signal_names = (const char **) malloc (nbytes)) != NULL)
        {
        {
          memset (signal_names, 0, nbytes);
          memset (signal_names, 0, nbytes);
          for (eip = signal_table; eip -> name != NULL; eip++)
          for (eip = signal_table; eip -> name != NULL; eip++)
            {
            {
              signal_names[eip -> value] = eip -> name;
              signal_names[eip -> value] = eip -> name;
            }
            }
        }
        }
    }
    }
 
 
#ifndef HAVE_SYS_SIGLIST
#ifndef HAVE_SYS_SIGLIST
 
 
  /* Now attempt to allocate the sys_siglist table, zero it out, and then
  /* Now attempt to allocate the sys_siglist table, zero it out, and then
     initialize it from the statically initialized signal_table. */
     initialize it from the statically initialized signal_table. */
 
 
  if (sys_siglist == NULL)
  if (sys_siglist == NULL)
    {
    {
      nbytes = num_signal_names * sizeof (char *);
      nbytes = num_signal_names * sizeof (char *);
      if ((sys_siglist = (const char **) malloc (nbytes)) != NULL)
      if ((sys_siglist = (const char **) malloc (nbytes)) != NULL)
        {
        {
          memset (sys_siglist, 0, nbytes);
          memset (sys_siglist, 0, nbytes);
          sys_nsig = num_signal_names;
          sys_nsig = num_signal_names;
          for (eip = signal_table; eip -> name != NULL; eip++)
          for (eip = signal_table; eip -> name != NULL; eip++)
            {
            {
              sys_siglist[eip -> value] = eip -> msg;
              sys_siglist[eip -> value] = eip -> msg;
            }
            }
        }
        }
    }
    }
 
 
#endif
#endif
 
 
}
}
 
 
 
 
/*
/*
 
 
NAME
NAME
 
 
        signo_max -- return the max signo value
        signo_max -- return the max signo value
 
 
SYNOPSIS
SYNOPSIS
 
 
        int signo_max ();
        int signo_max ();
 
 
DESCRIPTION
DESCRIPTION
 
 
        Returns the maximum signo value for which a corresponding symbolic
        Returns the maximum signo value for which a corresponding symbolic
        name or message is available.  Note that in the case where
        name or message is available.  Note that in the case where
        we use the sys_siglist supplied by the system, it is possible for
        we use the sys_siglist supplied by the system, it is possible for
        there to be more symbolic names than messages, or vice versa.
        there to be more symbolic names than messages, or vice versa.
        In fact, the manual page for psignal(3b) explicitly warns that one
        In fact, the manual page for psignal(3b) explicitly warns that one
        should check the size of the table (NSIG) before indexing it,
        should check the size of the table (NSIG) before indexing it,
        since new signal codes may be added to the system before they are
        since new signal codes may be added to the system before they are
        added to the table.  Thus NSIG might be smaller than value
        added to the table.  Thus NSIG might be smaller than value
        implied by the largest signo value defined in <signal.h>.
        implied by the largest signo value defined in <signal.h>.
 
 
        We return the maximum value that can be used to obtain a meaningful
        We return the maximum value that can be used to obtain a meaningful
        symbolic name or message.
        symbolic name or message.
 
 
*/
*/
 
 
int
int
signo_max ()
signo_max ()
{
{
  int maxsize;
  int maxsize;
 
 
  if (signal_names == NULL)
  if (signal_names == NULL)
    {
    {
      init_signal_tables ();
      init_signal_tables ();
    }
    }
  maxsize = MAX (sys_nsig, num_signal_names);
  maxsize = MAX (sys_nsig, num_signal_names);
  return (maxsize - 1);
  return (maxsize - 1);
}
}
 
 
 
 
/*
/*
 
 
NAME
NAME
 
 
        strsignal -- map a signal number to a signal message string
        strsignal -- map a signal number to a signal message string
 
 
SYNOPSIS
SYNOPSIS
 
 
        const char *strsignal (int signo)
        const char *strsignal (int signo)
 
 
DESCRIPTION
DESCRIPTION
 
 
        Maps an signal number to an signal message string, the contents of
        Maps an signal number to an signal message string, the contents of
        which are implementation defined.  On systems which have the external
        which are implementation defined.  On systems which have the external
        variable sys_siglist, these strings will be the same as the ones used
        variable sys_siglist, these strings will be the same as the ones used
        by psignal().
        by psignal().
 
 
        If the supplied signal number is within the valid range of indices
        If the supplied signal number is within the valid range of indices
        for the sys_siglist, but no message is available for the particular
        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, then returns the string "Signal NUM", where NUM is the
        signal number.
        signal number.
 
 
        If the supplied signal number is not a valid index into sys_siglist,
        If the supplied signal number is not a valid index into sys_siglist,
        returns NULL.
        returns NULL.
 
 
        The returned string is only guaranteed to be valid only until the
        The returned string is only guaranteed to be valid only until the
        next call to strsignal.
        next call to strsignal.
 
 
*/
*/
 
 
#ifndef HAVE_STRSIGNAL
#ifndef HAVE_STRSIGNAL
 
 
const char *
const char *
strsignal (signo)
strsignal (signo)
  int signo;
  int signo;
{
{
  const char *msg;
  const char *msg;
  static char buf[32];
  static char buf[32];
 
 
#ifndef HAVE_SYS_SIGLIST
#ifndef HAVE_SYS_SIGLIST
 
 
  if (signal_names == NULL)
  if (signal_names == NULL)
    {
    {
      init_signal_tables ();
      init_signal_tables ();
    }
    }
 
 
#endif
#endif
 
 
  if ((signo < 0) || (signo >= sys_nsig))
  if ((signo < 0) || (signo >= sys_nsig))
    {
    {
      /* Out of range, just return NULL */
      /* Out of range, just return NULL */
      msg = NULL;
      msg = NULL;
    }
    }
  else if ((sys_siglist == NULL) || (sys_siglist[signo] == NULL))
  else if ((sys_siglist == NULL) || (sys_siglist[signo] == NULL))
    {
    {
      /* In range, but no sys_siglist or no entry at this index. */
      /* In range, but no sys_siglist or no entry at this index. */
      sprintf (buf, "Signal %d", signo);
      sprintf (buf, "Signal %d", signo);
      msg = (const char *) buf;
      msg = (const char *) buf;
    }
    }
  else
  else
    {
    {
      /* In range, and a valid message.  Just return the message. */
      /* In range, and a valid message.  Just return the message. */
      msg = (const char *) sys_siglist[signo];
      msg = (const char *) sys_siglist[signo];
    }
    }
 
 
  return (msg);
  return (msg);
}
}
 
 
#endif /* ! HAVE_STRSIGNAL */
#endif /* ! HAVE_STRSIGNAL */
 
 
/*
/*
 
 
NAME
NAME
 
 
        strsigno -- map an signal number to a symbolic name string
        strsigno -- map an signal number to a symbolic name string
 
 
SYNOPSIS
SYNOPSIS
 
 
        const char *strsigno (int signo)
        const char *strsigno (int signo)
 
 
DESCRIPTION
DESCRIPTION
 
 
        Given an signal number, returns a pointer to a string containing
        Given an signal number, returns a pointer to a string containing
        the symbolic name of that signal number, as found in <signal.h>.
        the symbolic name of that signal number, as found in <signal.h>.
 
 
        If the supplied signal number is within the valid range of indices
        If the supplied signal number is within the valid range of indices
        for symbolic names, but no name is available for the particular
        for symbolic names, but no name is available for the particular
        signal number, then returns the string "Signal NUM", where NUM is
        signal number, then returns the string "Signal NUM", where NUM is
        the signal number.
        the signal number.
 
 
        If the supplied signal number is not within the range of valid
        If the supplied signal number is not within the range of valid
        indices, then returns NULL.
        indices, then returns NULL.
 
 
BUGS
BUGS
 
 
        The contents of the location pointed to are only guaranteed to be
        The contents of the location pointed to are only guaranteed to be
        valid until the next call to strsigno.
        valid until the next call to strsigno.
 
 
*/
*/
 
 
const char *
const char *
strsigno (signo)
strsigno (signo)
  int signo;
  int signo;
{
{
  const char *name;
  const char *name;
  static char buf[32];
  static char buf[32];
 
 
  if (signal_names == NULL)
  if (signal_names == NULL)
    {
    {
      init_signal_tables ();
      init_signal_tables ();
    }
    }
 
 
  if ((signo < 0) || (signo >= num_signal_names))
  if ((signo < 0) || (signo >= num_signal_names))
    {
    {
      /* Out of range, just return NULL */
      /* Out of range, just return NULL */
      name = NULL;
      name = NULL;
    }
    }
  else if ((signal_names == NULL) || (signal_names[signo] == NULL))
  else if ((signal_names == NULL) || (signal_names[signo] == NULL))
    {
    {
      /* In range, but no signal_names or no entry at this index. */
      /* In range, but no signal_names or no entry at this index. */
      sprintf (buf, "Signal %d", signo);
      sprintf (buf, "Signal %d", signo);
      name = (const char *) buf;
      name = (const char *) buf;
    }
    }
  else
  else
    {
    {
      /* In range, and a valid name.  Just return the name. */
      /* In range, and a valid name.  Just return the name. */
      name = signal_names[signo];
      name = signal_names[signo];
    }
    }
 
 
  return (name);
  return (name);
}
}
 
 
 
 
/*
/*
 
 
NAME
NAME
 
 
        strtosigno -- map a symbolic signal name to a numeric value
        strtosigno -- map a symbolic signal name to a numeric value
 
 
SYNOPSIS
SYNOPSIS
 
 
        int strtosigno (char *name)
        int strtosigno (char *name)
 
 
DESCRIPTION
DESCRIPTION
 
 
        Given the symbolic name of a signal, map it to a signal number.
        Given the symbolic name of a signal, map it to a signal number.
        If no translation is found, returns 0.
        If no translation is found, returns 0.
 
 
*/
*/
 
 
int
int
strtosigno (name)
strtosigno (name)
     const char *name;
     const char *name;
{
{
  int signo = 0;
  int signo = 0;
 
 
  if (name != NULL)
  if (name != NULL)
    {
    {
      if (signal_names == NULL)
      if (signal_names == NULL)
        {
        {
          init_signal_tables ();
          init_signal_tables ();
        }
        }
      for (signo = 0; signo < num_signal_names; signo++)
      for (signo = 0; signo < num_signal_names; signo++)
        {
        {
          if ((signal_names[signo] != NULL) &&
          if ((signal_names[signo] != NULL) &&
              (strcmp (name, signal_names[signo]) == 0))
              (strcmp (name, signal_names[signo]) == 0))
            {
            {
              break;
              break;
            }
            }
        }
        }
      if (signo == num_signal_names)
      if (signo == num_signal_names)
        {
        {
          signo = 0;
          signo = 0;
        }
        }
    }
    }
  return (signo);
  return (signo);
}
}
 
 
 
 
/*
/*
 
 
NAME
NAME
 
 
        psignal -- print message about signal to stderr
        psignal -- print message about signal to stderr
 
 
SYNOPSIS
SYNOPSIS
 
 
        void psignal (unsigned signo, char *message);
        void psignal (unsigned signo, char *message);
 
 
DESCRIPTION
DESCRIPTION
 
 
        Print to the standard error the message, followed by a colon,
        Print to the standard error the message, followed by a colon,
        followed by the description of the signal specified by signo,
        followed by the description of the signal specified by signo,
        followed by a newline.
        followed by a newline.
*/
*/
 
 
#ifndef HAVE_PSIGNAL
#ifndef HAVE_PSIGNAL
 
 
void
void
psignal (signo, message)
psignal (signo, message)
  unsigned signo;
  unsigned signo;
  char *message;
  char *message;
{
{
  if (signal_names == NULL)
  if (signal_names == NULL)
    {
    {
      init_signal_tables ();
      init_signal_tables ();
    }
    }
  if ((signo <= 0) || (signo >= sys_nsig))
  if ((signo <= 0) || (signo >= sys_nsig))
    {
    {
      fprintf (stderr, "%s: unknown signal\n", message);
      fprintf (stderr, "%s: unknown signal\n", message);
    }
    }
  else
  else
    {
    {
      fprintf (stderr, "%s: %s\n", message, sys_siglist[signo]);
      fprintf (stderr, "%s: %s\n", message, sys_siglist[signo]);
    }
    }
}
}
 
 
#endif  /* ! HAVE_PSIGNAL */
#endif  /* ! HAVE_PSIGNAL */
 
 
 
 
/* A simple little main that does nothing but print all the signal translations
/* A simple little main that does nothing but print all the signal translations
   if MAIN is defined and this file is compiled and linked. */
   if MAIN is defined and this file is compiled and linked. */
 
 
#ifdef MAIN
#ifdef MAIN
 
 
#include <stdio.h>
#include <stdio.h>
 
 
int
int
main ()
main ()
{
{
  int signo;
  int signo;
  int maxsigno;
  int maxsigno;
  const char *name;
  const char *name;
  const char *msg;
  const char *msg;
 
 
  maxsigno = signo_max ();
  maxsigno = signo_max ();
  printf ("%d entries in names table.\n", num_signal_names);
  printf ("%d entries in names table.\n", num_signal_names);
  printf ("%d entries in messages table.\n", sys_nsig);
  printf ("%d entries in messages table.\n", sys_nsig);
  printf ("%d is max useful index.\n", maxsigno);
  printf ("%d is max useful index.\n", maxsigno);
 
 
  /* Keep printing values until we get to the end of *both* tables, not
  /* Keep printing values until we get to the end of *both* tables, not
     *either* table.  Note that knowing the maximum useful index does *not*
     *either* table.  Note that knowing the maximum useful index does *not*
     relieve us of the responsibility of testing the return pointer for
     relieve us of the responsibility of testing the return pointer for
     NULL. */
     NULL. */
 
 
  for (signo = 0; signo <= maxsigno; signo++)
  for (signo = 0; signo <= maxsigno; signo++)
    {
    {
      name = strsigno (signo);
      name = strsigno (signo);
      name = (name == NULL) ? "<NULL>" : name;
      name = (name == NULL) ? "<NULL>" : name;
      msg = strsignal (signo);
      msg = strsignal (signo);
      msg = (msg == NULL) ? "<NULL>" : msg;
      msg = (msg == NULL) ? "<NULL>" : msg;
      printf ("%-4d%-18s%s\n", signo, name, msg);
      printf ("%-4d%-18s%s\n", signo, name, msg);
    }
    }
 
 
  return 0;
  return 0;
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.