X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=libiberty%2Fstrerror.c;h=cc7692c1d6951ce7008b59d7f93766777d256547;hb=1087441f0712681bf0c30d104870ea299aa326c1;hp=0dd2220cd73d88840b7e8f003a6484768f10e55e;hpb=5c82d20a26d0b283c831dba782731b4273f4d4d8;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/strerror.c b/libiberty/strerror.c index 0dd2220cd7..cc7692c1d6 100644 --- a/libiberty/strerror.c +++ b/libiberty/strerror.c @@ -2,9 +2,6 @@ Written by Fred Fish. fnf@cygnus.com This file is in the public domain. --Per Bothner. */ -#include "ansidecl.h" -#include "libiberty.h" - #include "config.h" #ifdef HAVE_SYS_ERRLIST @@ -13,13 +10,18 @@ incompatible with our later declaration, perhaps by using const attributes. So we hide the declaration in errno.h (if any) using a macro. */ +#define sys_nerr sys_nerr__ #define sys_errlist sys_errlist__ #endif +#include "ansidecl.h" +#include "libiberty.h" + #include #include #ifdef HAVE_SYS_ERRLIST +#undef sys_nerr #undef sys_errlist #endif @@ -41,7 +43,7 @@ extern PTR memset (); # define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif -static void init_error_tables PARAMS ((void)); +static void init_error_tables (void); /* Translation table for errno values. See intro(2) in most UNIX systems Programmers Reference Manuals. @@ -56,10 +58,10 @@ static void init_error_tables PARAMS ((void)); struct error_info { - int value; /* The numeric value from */ - const char *name; /* The equivalent symbolic value */ + const int value; /* The numeric value from */ + const char *const name; /* The equivalent symbolic value */ #ifndef HAVE_SYS_ERRLIST - const char *msg; /* Short message about this value */ + const char *const msg; /* Short message about this value */ #endif }; @@ -297,7 +299,7 @@ static const struct error_info error_table[] = ENTRY(EREMCHG, "EREMCHG", "Remote address changed"), #endif #if defined (ELIBACC) - ENTRY(ELIBACC, "ELIBACC", "Can not access a needed shared library"), + ENTRY(ELIBACC, "ELIBACC", "Cannot access a needed shared library"), #endif #if defined (ELIBBAD) ENTRY(ELIBBAD, "ELIBBAD", "Accessing a corrupted shared library"), @@ -460,16 +462,22 @@ static int num_error_names = 0; #ifndef HAVE_SYS_ERRLIST +#define sys_nerr sys_nerr__ +#define sys_errlist sys_errlist__ static int sys_nerr; static const char **sys_errlist; #else + +#ifndef sys_nerr extern int sys_nerr; +#endif +#ifndef sys_errlist extern char *sys_errlist[]; - #endif +#endif /* @@ -500,7 +508,7 @@ BUGS */ static void -init_error_tables () +init_error_tables (void) { const struct error_info *eip; int nbytes; @@ -560,33 +568,28 @@ init_error_tables () /* -NAME - errno_max -- return the max errno value +@deftypefn Extension int errno_max (void) -SYNOPSIS +Returns the maximum @code{errno} value for which a corresponding +symbolic name or message is available. Note that in the case where we +use the @code{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 @code{perror(3C)} explicitly warns that one +should check the size of the table (@code{sys_nerr}) before indexing +it, since new error codes may be added to the system before they are +added to the table. Thus @code{sys_nerr} might be smaller than value +implied by the largest @code{errno} value defined in @code{}. - int errno_max (); +We return the maximum value that can be used to obtain a meaningful +symbolic name or message. -DESCRIPTION - - Returns the maximum errno value for which a corresponding symbolic - name or message is available. Note that in the case where - 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 . - - We return the maximum value that can be used to obtain a meaningful - symbolic name or message. +@end deftypefn */ int -errno_max () +errno_max (void) { int maxsize; @@ -602,39 +605,32 @@ errno_max () /* -NAME - - strerror -- map an error number to an error message string +@deftypefn Supplemental char* strerror (int @var{errnoval}) -SYNOPSIS - - char *strerror (int errnoval) +Maps an @code{errno} number to an error message string, the contents +of which are implementation defined. On systems which have the +external variables @code{sys_nerr} and @code{sys_errlist}, these +strings will be the same as the ones used by @code{perror}. -DESCRIPTION +If the supplied error number is within the valid range of indices for +the @code{sys_errlist}, but no message is available for the particular +error number, then returns the string @samp{Error @var{num}}, where +@var{num} is the error number. - Maps an errno number to an error message string, the contents of - which are implementation defined. On systems which have the external - variables sys_nerr and sys_errlist, these strings will be the same - as the ones used by perror(). +If the supplied error number is not a valid index into +@code{sys_errlist}, returns @code{NULL}. - 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. +The returned string is only guaranteed to be valid only until the +next call to @code{strerror}. - If the supplied error number is not a valid index into sys_errlist, - returns NULL. - - The returned string is only guaranteed to be valid only until the - next call to strerror. +@end deftypefn */ char * -strerror (errnoval) - int errnoval; +strerror (int errnoval) { - char *msg; + const char *msg; static char buf[32]; #ifndef HAVE_SYS_ERRLIST @@ -676,38 +672,29 @@ strerror (errnoval) /* -NAME - - strerrno -- map an error number to a symbolic name string - -SYNOPSIS - - const char *strerrno (int errnoval) +@deftypefn Replacement {const char*} strerrno (int @var{errnum}) -DESCRIPTION - - Given an error number returned from a system call (typically - returned in errno), returns a pointer to a string containing the - symbolic name of that error number, as found in . +Given an error number returned from a system call (typically returned +in @code{errno}), returns a pointer to a string containing the +symbolic name of that error number, as found in @code{}. - 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. +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 @samp{Error @var{num}}, where @var{num} +is the error number. - If the supplied error number is not within the range of valid - indices, then returns NULL. +If the supplied error number is not within the range of valid +indices, then returns @code{NULL}. -BUGS +The contents of the location pointed to are only guaranteed to be +valid until the next call to @code{strerrno}. - The contents of the location pointed to are only guaranteed to be - valid until the next call to strerrno. +@end deftypefn */ const char * -strerrno (errnoval) - int errnoval; +strerrno (int errnoval) { const char *name; static char buf[32]; @@ -744,24 +731,17 @@ strerrno (errnoval) /* -NAME - - strtoerrno -- map a symbolic errno name to a numeric value +@deftypefn Extension int strtoerrno (const char *@var{name}) -SYNOPSIS - - int strtoerrno (char *name) - -DESCRIPTION +Given the symbolic name of a error number (e.g., @code{EACCES}), map it +to an errno value. If no translation is found, returns 0. - Given the symbolic name of a error number, map it to an errno value. - If no translation is found, returns 0. +@end deftypefn */ int -strtoerrno (name) - const char *name; +strtoerrno (const char *name) { int errnoval = 0; @@ -801,12 +781,12 @@ strtoerrno (name) #include int -main () +main (void) { int errn; int errnmax; const char *name; - char *msg; + const char *msg; char *strerror (); errnmax = errno_max ();