123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include <errno.h>
- #include <string.h>
- #include <stdio.h>
- #include <gpxe/errortab.h>
-
-
-
- FILE_LICENCE ( GPL2_OR_LATER );
-
-
- static struct errortab * find_error ( int errno, int mask ) {
- struct errortab *errortab;
-
- for_each_table_entry ( errortab, ERRORTAB ) {
- if ( ( ( errortab->errno ^ errno ) & mask ) == 0 )
- return errortab;
- }
-
- return NULL;
- }
-
-
- static struct errortab * find_closest_error ( int errno ) {
- struct errortab *errortab;
-
-
- if ( ( errortab = find_error ( errno, 0x7fffffff ) ) != NULL )
- return errortab;
-
-
-
- if ( ( errortab = find_error ( errno, 0x4f0000ff ) ) != NULL )
- return errortab;
-
- return NULL;
- }
-
-
- const char * strerror ( int errno ) {
- static char errbuf[64];
- struct errortab *errortab;
-
-
- if ( errno < 0 )
- errno = -errno;
-
-
- errortab = find_closest_error ( errno );
-
-
- if ( errortab ) {
- snprintf ( errbuf, sizeof ( errbuf ), "%s (%#08x)",
- errortab->text, errno );
- } else {
- snprintf ( errbuf, sizeof ( errbuf ), "Error %#08x", errno );
- }
-
- return errbuf;
- }
-
-
- #undef ERRFILE
- #define ERRFILE 0
-
-
- struct errortab common_errors[] __errortab = {
- { 0, "No error" },
- { EACCES, "Permission denied" },
- { ECANCELED, "Operation cancelled" },
- { ECONNRESET, "Connection reset" },
- { EINVAL, "Invalid argument" },
- { EIO, "Input/output error" },
- { ENETUNREACH, "Network unreachable" },
- { ENODEV, "No such device" },
- { ENOENT, "File not found" },
- { ENOEXEC, "Not an executable image" },
- { ENOMEM, "Out of memory" },
- { ENOSPC, "No space left on device" },
- { ENOTCONN, "Not connected" },
- { ENOTSUP, "Not supported" },
- { EPERM, "Operation not permitted" },
- { ERANGE, "Out of range" },
- { ETIMEDOUT, "Connection timed out" },
- };
|