/[gnats]/gnats/libiberty/strerror.c
ViewVC logotype

Diff of /gnats/libiberty/strerror.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by pdm, Mon Dec 10 23:03:26 2001 UTC revision 1.4 by chewie, Sat Nov 13 05:14:17 2004 UTC
# Line 58  static void init_error_tables PARAMS ((v Line 58  static void init_error_tables PARAMS ((v
58    
59  struct error_info  struct error_info
60  {  {
61    int value;            /* The numeric value from <errno.h> */    const int value;              /* The numeric value from <errno.h> */
62    const char *name;     /* The equivalent symbolic value */    const char *const name;       /* The equivalent symbolic value */
63  #ifndef HAVE_SYS_ERRLIST  #ifndef HAVE_SYS_ERRLIST
64    const char *msg;      /* Short message about this value */    const char *const msg;        /* Short message about this value */
65  #endif  #endif
66  };  };
67    
# Line 462  static int num_error_names = 0; Line 462  static int num_error_names = 0;
462    
463  #ifndef HAVE_SYS_ERRLIST  #ifndef HAVE_SYS_ERRLIST
464    
465    #define sys_nerr sys_nerr__
466    #define sys_errlist sys_errlist__
467  static int sys_nerr;  static int sys_nerr;
468  static const char **sys_errlist;  static const char **sys_errlist;
469    
# Line 472  extern char *sys_errlist[]; Line 474  extern char *sys_errlist[];
474    
475  #endif  #endif
476    
   
477  /*  /*
478    
479  NAME  NAME
# Line 562  init_error_tables () Line 563  init_error_tables ()
563    
564  /*  /*
565    
 NAME  
   
         errno_max -- return the max errno value  
566    
567  SYNOPSIS  @deftypefn Extension int errno_max (void)
   
         int errno_max ();  
568    
569  DESCRIPTION  Returns the maximum @code{errno} value for which a corresponding
570    symbolic name or message is available.  Note that in the case where we
571    use the @code{sys_errlist} supplied by the system, it is possible for
572    there to be more symbolic names than messages, or vice versa.  In
573    fact, the manual page for @code{perror(3C)} explicitly warns that one
574    should check the size of the table (@code{sys_nerr}) before indexing
575    it, since new error codes may be added to the system before they are
576    added to the table.  Thus @code{sys_nerr} might be smaller than value
577    implied by the largest @code{errno} value defined in @code{<errno.h>}.
578    
579          Returns the maximum errno value for which a corresponding symbolic  We return the maximum value that can be used to obtain a meaningful
580          name or message is available.  Note that in the case where  symbolic name or message.
         we use the sys_errlist 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 perror(3C) explicitly warns that one  
         should check the size of the table (sys_nerr) before indexing it,  
         since new error codes may be added to the system before they are  
         added to the table.  Thus sys_nerr might be smaller than value  
         implied by the largest errno value defined in <errno.h>.  
581    
582          We return the maximum value that can be used to obtain a meaningful  @end deftypefn
         symbolic name or message.  
583    
584  */  */
585    
# Line 604  errno_max () Line 600  errno_max ()
600    
601  /*  /*
602    
603  NAME  @deftypefn Supplemental char* strerror (int @var{errnoval})
   
         strerror -- map an error number to an error message string  
   
 SYNOPSIS  
604    
605          char *strerror (int errnoval)  Maps an @code{errno} number to an error message string, the contents
606    of which are implementation defined.  On systems which have the
607    external variables @code{sys_nerr} and @code{sys_errlist}, these
608    strings will be the same as the ones used by @code{perror}.
609    
610  DESCRIPTION  If the supplied error number is within the valid range of indices for
611    the @code{sys_errlist}, but no message is available for the particular
612    error number, then returns the string @samp{Error @var{num}}, where
613    @var{num} is the error number.
614    
615          Maps an errno number to an error message string, the contents of  If the supplied error number is not a valid index into
616          which are implementation defined.  On systems which have the external  @code{sys_errlist}, returns @code{NULL}.
         variables sys_nerr and sys_errlist, these strings will be the same  
         as the ones used by perror().  
   
         If the supplied error number is within the valid range of indices  
         for the sys_errlist, but no message is available for the particular  
         error number, then returns the string "Error NUM", where NUM is the  
         error number.  
617    
618          If the supplied error number is not a valid index into sys_errlist,  The returned string is only guaranteed to be valid only until the
619          returns NULL.  next call to @code{strerror}.
620    
621          The returned string is only guaranteed to be valid only until the  @end deftypefn
         next call to strerror.  
622    
623  */  */
624    
# Line 636  char * Line 626  char *
626  strerror (errnoval)  strerror (errnoval)
627    int errnoval;    int errnoval;
628  {  {
629    char *msg;    const char *msg;
630    static char buf[32];    static char buf[32];
631    
632  #ifndef HAVE_SYS_ERRLIST  #ifndef HAVE_SYS_ERRLIST
# Line 678  strerror (errnoval) Line 668  strerror (errnoval)
668    
669  /*  /*
670    
671  NAME  @deftypefn Replacement {const char*} strerrno (int @var{errnum})
   
         strerrno -- map an error number to a symbolic name string  
   
 SYNOPSIS  
   
         const char *strerrno (int errnoval)  
672    
673  DESCRIPTION  Given an error number returned from a system call (typically returned
674    in @code{errno}), returns a pointer to a string containing the
675    symbolic name of that error number, as found in @code{<errno.h>}.
676    
677          Given an error number returned from a system call (typically  If the supplied error number is within the valid range of indices for
678          returned in errno), returns a pointer to a string containing the  symbolic names, but no name is available for the particular error
679          symbolic name of that error number, as found in <errno.h>.  number, then returns the string @samp{Error @var{num}}, where @var{num}
680    is the error number.
         If the supplied error number is within the valid range of indices  
         for symbolic names, but no name is available for the particular  
         error number, then returns the string "Error NUM", where NUM is  
         the error number.  
681    
682          If the supplied error number is not within the range of valid  If the supplied error number is not within the range of valid
683          indices, then returns NULL.  indices, then returns @code{NULL}.
684    
685  BUGS  The contents of the location pointed to are only guaranteed to be
686    valid until the next call to @code{strerrno}.
687    
688          The contents of the location pointed to are only guaranteed to be  @end deftypefn
         valid until the next call to strerrno.  
689    
690  */  */
691    
# Line 746  strerrno (errnoval) Line 728  strerrno (errnoval)
728    
729  /*  /*
730    
731  NAME  @deftypefn Extension int strtoerrno (const char *@var{name})
   
         strtoerrno -- map a symbolic errno name to a numeric value  
   
 SYNOPSIS  
   
         int strtoerrno (char *name)  
732    
733  DESCRIPTION  Given the symbolic name of a error number (e.g., @code{EACCES}), map it
734    to an errno value.  If no translation is found, returns 0.
735    
736          Given the symbolic name of a error number, map it to an errno value.  @end deftypefn
         If no translation is found, returns 0.  
737    
738  */  */
739    
# Line 808  main () Line 784  main ()
784    int errn;    int errn;
785    int errnmax;    int errnmax;
786    const char *name;    const char *name;
787    char *msg;    const char *msg;
788    char *strerror ();    char *strerror ();
789    
790    errnmax = errno_max ();    errnmax = errno_max ();

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26