From 07ad92f856c98327f2219a4211516257dcf88f23 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 9 Nov 2010 08:32:19 +0000 Subject: Tidied up err.c --- err.c | 55 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/err.c b/err.c index 2ae6008..3173b01 100644 --- a/err.c +++ b/err.c @@ -1,36 +1,55 @@ /* Report Unix errors */ +#include #include +#include #include -#if 0 -extern int sys_nerr; -extern char *sys_errlist[]; -#endif - -main(argc,argv) -int argc; -char *argv[]; - +int main(int argc, char *argv[]) { int f,n; + char *p; - if (argc==1) - { + if (argc == 1) + { fprintf(stderr,"%s:usage %s -t|err1 [.. errn]\n",argv[0],argv[0]); - exit(1); - } + exit(EXIT_FAILURE); + } if (!strcmp(argv[1],"-t")) - for(f=0;f=sys_nerr) + errno = 0; + + p = strerror(n); + + if (errno == EINVAL) + { fprintf(stderr,"%s:errcode %d invalid!\n",argv[0],n); + } else - printf("%3d : %s\n",n,sys_errlist[n]); + { + printf("%3d : %s\n",n,p); } + } + } + + return EXIT_SUCCESS; } -- cgit v1.2.3