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
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 FILE_LICENCE ( GPL2_OR_LATER );
00022
00023
00024
00025
00026
00027
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
00042
00043
00044
00045
00046
00047
00048 static struct errortab * find_closest_error ( int errno ) {
00049 struct errortab *errortab;
00050
00051
00052 if ( ( errortab = find_error ( errno ) ) != NULL )
00053 return errortab;
00054
00055
00056
00057
00058 if ( ( errortab = find_error ( errno & 0x7f0000ff ) ) != NULL )
00059 return errortab;
00060
00061 return NULL;
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 const char * strerror ( int errno ) {
00078 static char errbuf[64];
00079 struct errortab *errortab;
00080
00081
00082 if ( errno < 0 )
00083 errno = -errno;
00084
00085
00086 errortab = find_closest_error ( errno );
00087
00088
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
00100 #undef ERRFILE
00101 #define ERRFILE 0
00102
00103
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 };