strerror.c

Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <string.h>
00003 #include <stdio.h>
00004 #include <gpxe/errortab.h>
00005 
00006 /** @file
00007  *
00008  * Error descriptions.
00009  *
00010  * The error numbers used by Etherboot are a superset of those defined
00011  * by the PXE specification version 2.1.  See errno.h for a listing of
00012  * the error values.
00013  *
00014  * To save space in ROM images, error string tables are optional.  Use
00015  * the ERRORMSG_XXX options in config.h to select which error string
00016  * tables you want to include.  If an error string table is omitted,
00017  * strerror() will simply return the text "Error 0x<errno>".
00018  *
00019  */
00020 
00021 FILE_LICENCE ( GPL2_OR_LATER );
00022 
00023 /**
00024  * Find error description
00025  *
00026  * @v errno             Error number
00027  * @ret errortab        Error description, or NULL
00028  */
00029 static struct errortab * find_error ( int errno ) {
00030         struct errortab *errortab;
00031 
00032         for_each_table_entry ( errortab, ERRORTAB ) {
00033                 if ( errortab->errno == errno )
00034                         return errortab;
00035         }
00036 
00037         return NULL;
00038 }
00039 
00040 /**
00041  * Find closest error description
00042  *
00043  * @v errno             Error number
00044  * @ret errortab        Error description, or NULL
00045  *
00046  * 
00047  */
00048 static struct errortab * find_closest_error ( int errno ) {
00049         struct errortab *errortab;
00050 
00051         /* First, look for an exact match */
00052         if ( ( errortab = find_error ( errno ) ) != NULL )
00053                 return errortab;
00054 
00055         /* Second, try masking off the gPXE-specific bit and seeing if
00056          * we have an entry for the generic POSIX error message.
00057          */
00058         if ( ( errortab = find_error ( errno & 0x7f0000ff ) ) != NULL )
00059                 return errortab;
00060 
00061         return NULL;
00062 }
00063 
00064 /**
00065  * Retrieve string representation of error number.
00066  *
00067  * @v errno/rc          Error number or return status code
00068  * @ret strerror        Pointer to error text
00069  *
00070  * If the error is not found in the linked-in error tables, generates
00071  * a generic "Error 0x<errno>" message.
00072  *
00073  * The pointer returned by strerror() is valid only until the next
00074  * call to strerror().
00075  *
00076  */
00077 const char * strerror ( int errno ) {
00078         static char errbuf[64];
00079         struct errortab *errortab;
00080 
00081         /* Allow for strerror(rc) as well as strerror(errno) */
00082         if ( errno < 0 )
00083                 errno = -errno;
00084 
00085         /* Find the error description, if one exists */
00086         errortab = find_closest_error ( errno );
00087 
00088         /* Construct the error message */
00089         if ( errortab ) {
00090                 snprintf ( errbuf, sizeof ( errbuf ), "%s (%#08x)",
00091                            errortab->text, errno );
00092         } else {
00093                 snprintf ( errbuf, sizeof ( errbuf ), "Error %#08x", errno );
00094         }
00095 
00096         return errbuf;
00097 }
00098 
00099 /* Do not include ERRFILE portion in the numbers in the error table */
00100 #undef ERRFILE
00101 #define ERRFILE 0
00102 
00103 /** The most common errors */
00104 struct errortab common_errors[] __errortab = {
00105         { 0, "No error" },
00106         { EACCES, "Permission denied" },
00107         { ECANCELED, "Operation cancelled" },
00108         { ECONNRESET, "Connection reset" },
00109         { EINVAL, "Invalid argument" },
00110         { EIO, "Input/output error" },
00111         { ENETUNREACH, "Network unreachable" },
00112         { ENODEV, "No such device" },
00113         { ENOENT, "File not found" },
00114         { ENOEXEC, "Not an executable image" },
00115         { ENOMEM, "Out of memory" },
00116         { ENOSPC, "No space left on device" },
00117         { ENOTCONN, "Not connected" },
00118         { ENOTSUP, "Not supported" },
00119         { EPERM, "Operation not permitted" },
00120         { ERANGE, "Out of range" },
00121         { ETIMEDOUT, "Connection timed out" },
00122 };

Generated on Tue Apr 6 20:01:06 2010 for gPXE by  doxygen 1.5.7.1