From 9f7f0f7b9e9c57b11cb5c143d8bba1c8f5545ade Mon Sep 17 00:00:00 2001 From: hjp Date: Fri, 14 Feb 2003 15:45:28 +0000 Subject: [PATCH] Command line argument can now be a defined error code (e.g., EPERM) instead of an error number. Added Linux specific error codes --- errno/errno.c | 41 +++++++++++++++++++++++++++-------------- errno/errno.list | 25 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/errno/errno.c b/errno/errno.c index 5f64340..35bce1a 100644 --- a/errno/errno.c +++ b/errno/errno.c @@ -6,12 +6,6 @@ char *cmnd; -static void usage(void) { - fprintf(stderr, "Usage: %s errno ...\n", cmnd); - exit(1); -} - - int main(int argc, char **argv) { int i; @@ -26,18 +20,37 @@ int main(int argc, char **argv) { } } else { for (i = 1; i < argc; i++) { - int e = strtoul(argv[i], NULL, 0); - char *d = "(unknown)"; - int j; + char *p; + int e = strtoul(argv[i], &p, 0); - for (j = 0; j < wke_nr; j++) { - if (wke[j].number == e) { - d = wke[j].define; - break; + if (*p) { + /* This is not a number, so we assume it is a define */ + char *d = argv[i]; + int j; + + for (j = 0; j < wke_nr; j++) { + if (strcmp(wke[j].define, d) == 0) { + e = wke[j].number; + printf("%d\t%s\t%s\n", e, d, strerror(e)); + break; + } } + + } else { + /* it is a number */ + char *d = "(unknown)"; + int j; + + for (j = 0; j < wke_nr; j++) { + if (wke[j].number == e) { + d = wke[j].define; + break; + } + } + + printf("%d\t%s\t%s\n", e, d, strerror(e)); } - printf("%d\t%s\t%s\n", e, d, strerror(e)); } } return 0; diff --git a/errno/errno.list b/errno/errno.list index d828e0e..03580f6 100644 --- a/errno/errno.list +++ b/errno/errno.list @@ -6,9 +6,15 @@ EADV EAFNOSUPPORT EAGAIN EALREADY +EBADE EBADF +EBADFD EBADMSG +EBADR +EBADRQC +EBADSLT EBADVER +EBFONT EBUSY ECANCELED ECHILD @@ -19,6 +25,7 @@ ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK +EDEADLOCK EDESTADDRREQ EDOM EDOTDOT @@ -36,21 +43,30 @@ EINVAL EIO EISCONN EISDIR +EISNAM EL2HLT EL2NSYNC EL3HLT EL3RST +ELIBACC +ELIBBAD +ELIBEXEC +ELIBMAX +ELIBSCN ELNRNG ELOOP +EMEDIUMTYPE EMFILE EMLINK EMSGSIZE EMULTIHOP ENAMETOOLONG +ENAVAIL ENETDOWN ENETRESET ENETUNREACH ENFILE +ENOANO ENOBUFS ENOCSI ENODATA @@ -61,6 +77,7 @@ ENOLCK ENOLINK ENOLOAD ENOMATCH +ENOMEDIUM ENOMEM ENOMSG ENONET @@ -76,9 +93,11 @@ ENOTBLK ENOTCONN ENOTDIR ENOTEMPTY +ENOTNAM ENOTSOCK ENOTSUP ENOTTY +ENOTUNIQ ENOUNLD ENOUNREG ENXIO @@ -93,8 +112,11 @@ EPROTOTYPE ERANGE EREFUSED ERELOC +EREMCHG EREMOTE +EREMOTEIO EREMOTERELEASE +ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT @@ -102,11 +124,14 @@ ESPIPE ESRCH ESRMNT ESTALE +ESTRPIPE ETIME ETIMEDOUT ETOOMANYREFS ETXTBSY +EUCLEAN EUNATCH EUSERS EWOULDBLOCK EXDEV +EXFULL