Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Functions | Variables
strsignal.c File Reference
#include "config.h"
#include "ansidecl.h"
#include "libiberty.h"
#include <stdio.h>
#include <signal.h>

Go to the source code of this file.

Classes

struct  signal_info

Defines

#define sys_siglist   no_such_symbol
#define sys_nsig   sys_nsig__no_such_symbol
#define NULL   (void *) 0
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
#define ENTRY(value, name, msg)   {value, name, msg}

Functions

PTR malloc ()
PTR memset ()
static void init_signal_tables (void)
int signo_max (void)
const char * strsignal (int signo)
const char * strsigno (int signo)
int strtosigno (const char *name)
void psignal (int signo, char *message)

Variables

static struct signal_info []
static const char ** signal_names
static int num_signal_names = 0
static int sys_nsig
static const char ** sys_siglist

Class Documentation

struct signal_info

Definition at line 63 of file strsignal.c.

Class Members
const char *const msg
const char *const name
const int value

Define Documentation

#define ENTRY (   value,
  name,
  msg 
)    {value, name, msg}

Definition at line 73 of file strsignal.c.

#define MAX (   a,
  b 
)    ((a) > (b) ? (a) : (b))

Definition at line 48 of file strsignal.c.

#define NULL   (void *) 0

Definition at line 44 of file strsignal.c.

#define sys_nsig   sys_nsig__no_such_symbol

Definition at line 19 of file strsignal.c.

#define sys_siglist   no_such_symbol

Definition at line 18 of file strsignal.c.


Function Documentation

static void init_signal_tables ( void  ) [static]

Definition at line 287 of file strsignal.c.

{
  const struct signal_info *eip;
  int nbytes;

  /* If we haven't already scanned the signal_table once to find the maximum
     signal value, then go find it now. */

  if (num_signal_names == 0)
    {
      for (eip = signal_table; eip -> name != NULL; eip++)
       {
         if (eip -> value >= num_signal_names)
           {
             num_signal_names = eip -> value + 1;
           }
       }
    }

  /* Now attempt to allocate the signal_names table, zero it out, and then
     initialize it from the statically initialized signal_table. */

  if (signal_names == NULL)
    {
      nbytes = num_signal_names * sizeof (char *);
      if ((signal_names = (const char **) malloc (nbytes)) != NULL)
       {
         memset (signal_names, 0, nbytes);
         for (eip = signal_table; eip -> name != NULL; eip++)
           {
             signal_names[eip -> value] = eip -> name;
           }
       }
    }

#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. */

  if (sys_siglist == NULL)
    {
      nbytes = num_signal_names * sizeof (char *);
      if ((sys_siglist = (const char **) malloc (nbytes)) != NULL)
       {
         memset (sys_siglist, 0, nbytes);
         sys_nsig = num_signal_names;
         for (eip = signal_table; eip -> name != NULL; eip++)
           {
             sys_siglist[eip -> value] = eip -> msg;
           }
       }
    }

#endif

}

Here is the call graph for this function:

Here is the caller graph for this function:

PTR malloc ( )
PTR memset ( )
void psignal ( int  signo,
char *  message 
)

Definition at line 552 of file strsignal.c.

{
  if (signal_names == NULL)
    {
      init_signal_tables ();
    }
  if ((signo <= 0) || (signo >= sys_nsig))
    {
      fprintf (stderr, "%s: unknown signal\n", message);
    }
  else
    {
      fprintf (stderr, "%s: %s\n", message, sys_siglist[signo]);
    }
}

Here is the call graph for this function:

int signo_max ( void  )

Definition at line 368 of file strsignal.c.

{
  int maxsize;

  if (signal_names == NULL)
    {
      init_signal_tables ();
    }
  maxsize = MAX (sys_nsig, num_signal_names);
  return (maxsize - 1);
}

Here is the call graph for this function:

const char* strsignal ( int  signo)

Definition at line 408 of file strsignal.c.

{
  const char *msg;
  static char buf[32];

#ifndef HAVE_SYS_SIGLIST

  if (signal_names == NULL)
    {
      init_signal_tables ();
    }

#endif

  if ((signo < 0) || (signo >= sys_nsig))
    {
      /* Out of range, just return NULL */
      msg = NULL;
    }
  else if ((sys_siglist == NULL) || (sys_siglist[signo] == NULL))
    {
      /* In range, but no sys_siglist or no entry at this index. */
      sprintf (buf, "Signal %d", signo);
      msg = (const char *) buf;
    }
  else
    {
      /* In range, and a valid message.  Just return the message. */
      msg = (const char *) sys_siglist[signo];
    }
  
  return (msg);
}

Here is the call graph for this function:

const char* strsigno ( int  signo)

Definition at line 467 of file strsignal.c.

{
  const char *name;
  static char buf[32];

  if (signal_names == NULL)
    {
      init_signal_tables ();
    }

  if ((signo < 0) || (signo >= num_signal_names))
    {
      /* Out of range, just return NULL */
      name = NULL;
    }
  else if ((signal_names == NULL) || (signal_names[signo] == NULL))
    {
      /* In range, but no signal_names or no entry at this index. */
      sprintf (buf, "Signal %d", signo);
      name = (const char *) buf;
    }
  else
    {
      /* In range, and a valid name.  Just return the name. */
      name = signal_names[signo];
    }

  return (name);
}

Here is the call graph for this function:

int strtosigno ( const char *  name)

Definition at line 510 of file strsignal.c.

{
  int signo = 0;

  if (name != NULL)
    {
      if (signal_names == NULL)
       {
         init_signal_tables ();
       }
      for (signo = 0; signo < num_signal_names; signo++)
       {
         if ((signal_names[signo] != NULL) &&
             (strcmp (name, signal_names[signo]) == 0))
           {
             break;
           }
       }
      if (signo == num_signal_names)
       {
         signo = 0;
       }
    }
  return (signo);
}

Here is the call graph for this function:


Variable Documentation

int num_signal_names = 0 [static]

Definition at line 229 of file strsignal.c.

struct signal_info[] [static]

Definition at line 78 of file strsignal.c.

const char** signal_names [static]

Definition at line 228 of file strsignal.c.

int sys_nsig [static]

Definition at line 241 of file strsignal.c.

const char** sys_siglist [static]

Definition at line 242 of file strsignal.c.