Back to index

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

Go to the source code of this file.

Classes

struct  error_info

Defines

#define MAX(a, b)   ((a) > (b) ? (a) : (b))
#define ENTRY(value, name, msg)   {value, name, msg}
#define sys_nerr   sys_nerr__
#define sys_errlist   sys_errlist__

Functions

PTR malloc ()
PTR memset ()
static void init_error_tables (void)
int errno_max (void)
char * strerror (int errnoval)
const char * strerrno (int errnoval)
int strtoerrno (const char *name)

Variables

static struct error_info []
static const char ** error_names
static int num_error_names = 0
static int sys_nerr
static const char ** sys_errlist

Class Documentation

struct error_info

Definition at line 59 of file strerror.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 69 of file strerror.c.

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

Definition at line 43 of file strerror.c.

#define sys_errlist   sys_errlist__

Definition at line 466 of file strerror.c.

#define sys_nerr   sys_nerr__

Definition at line 465 of file strerror.c.


Function Documentation

int errno_max ( void  )

Definition at line 587 of file strerror.c.

{
  int maxsize;

  if (error_names == NULL)
    {
      init_error_tables ();
    }
  maxsize = MAX (sys_nerr, num_error_names);
  return (maxsize - 1);
}

Here is the call graph for this function:

static void init_error_tables ( void  ) [static]

Definition at line 506 of file strerror.c.

{
  const struct error_info *eip;
  int nbytes;

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

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

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

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

#ifndef HAVE_SYS_ERRLIST

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

  if (sys_errlist == NULL)
    {
      nbytes = num_error_names * sizeof (char *);
      if ((sys_errlist = (const char **) malloc (nbytes)) != NULL)
       {
         memset (sys_errlist, 0, nbytes);
         sys_nerr = num_error_names;
         for (eip = error_table; eip -> name != NULL; eip++)
           {
             sys_errlist[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 ( )
const char* strerrno ( int  errnoval)

Definition at line 692 of file strerror.c.

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

  if (error_names == NULL)
    {
      init_error_tables ();
    }

  if ((errnoval < 0) || (errnoval >= num_error_names))
    {
#ifdef EVMSERR
      if (errnoval == evmserr.value)
       name = evmserr.name;
      else
#endif
      /* Out of range, just return NULL */
      name = NULL;
    }
  else if ((error_names == NULL) || (error_names[errnoval] == NULL))
    {
      /* In range, but no error_names or no entry at this index. */
      sprintf (buf, "Error %d", errnoval);
      name = (const char *) buf;
    }
  else
    {
      /* In range, and a valid name.  Just return the name. */
      name = error_names[errnoval];
    }

  return (name);
}

Here is the call graph for this function:

char* strerror ( int  errnoval)

Definition at line 626 of file strerror.c.

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

#ifndef HAVE_SYS_ERRLIST

  if (error_names == NULL)
    {
      init_error_tables ();
    }

#endif

  if ((errnoval < 0) || (errnoval >= sys_nerr))
    {
#ifdef EVMSERR
      if (errnoval == evmserr.value)
       msg = evmserr.msg;
      else
#endif
      /* Out of range, just return NULL */
      msg = NULL;
    }
  else if ((sys_errlist == NULL) || (sys_errlist[errnoval] == NULL))
    {
      /* In range, but no sys_errlist or no entry at this index. */
      sprintf (buf, "Error %d", errnoval);
      msg = buf;
    }
  else
    {
      /* In range, and a valid message.  Just return the message. */
      msg = (char *) sys_errlist[errnoval];
    }
  
  return (msg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int strtoerrno ( const char *  name)

Definition at line 739 of file strerror.c.

{
  int errnoval = 0;

  if (name != NULL)
    {
      if (error_names == NULL)
       {
         init_error_tables ();
       }
      for (errnoval = 0; errnoval < num_error_names; errnoval++)
       {
         if ((error_names[errnoval] != NULL) &&
             (strcmp (name, error_names[errnoval]) == 0))
           {
             break;
           }
       }
      if (errnoval == num_error_names)
       {
#ifdef EVMSERR
         if (strcmp (name, evmserr.name) == 0)
           errnoval = evmserr.value;
         else
#endif
         errnoval = 0;
       }
    }
  return (errnoval);
}

Here is the call graph for this function:


Variable Documentation

struct error_info[] [static]

Definition at line 74 of file strerror.c.

const char** error_names [static]

Definition at line 452 of file strerror.c.

int num_error_names = 0 [static]

Definition at line 453 of file strerror.c.

const char** sys_errlist [static]

Definition at line 468 of file strerror.c.

int sys_nerr [static]

Definition at line 467 of file strerror.c.