summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--err.c55
1 files 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 <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <errno.h>
-#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;f++)
- printf("%3d : %s\n",f,sys_errlist[f]);
+ {
+ errno = 0;
+
+ for(f = 0; errno != EINVAL && f < 256; f++)
+ {
+ errno = 0;
+ p = strerror(f);
+
+ if (errno != EINVAL)
+ {
+ printf("%3d : %s\n",f,p);
+ }
+ }
+ }
else
+ {
for(f=1;f<argc;f++)
- {
+ {
n=strtol(argv[f],(char **)NULL,0);
- if(n>=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;
}