summaryrefslogtreecommitdiff
path: root/strerror.c
diff options
context:
space:
mode:
Diffstat (limited to 'strerror.c')
-rw-r--r--strerror.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/strerror.c b/strerror.c
index e7b1695..0e0359b 100644
--- a/strerror.c
+++ b/strerror.c
@@ -1,7 +1,18 @@
+#define _XOPEN_SOURCE 700
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include "strerror.h"
+
+const char *errname(int err)
+{
+ if (err < sizeof(errlist) / sizeof(errlist[0]) && errlist[err]) {
+ return errlist[err];
+ }
+ return "-";
+}
+
int main(int argc, char *argv[])
{
int n = 1;
@@ -13,7 +24,7 @@ int main(int argc, char *argv[])
do {
int err = atoi(argv[n]);
- printf("%d: %s\n", err, strerror(err));
+ printf("%d: %s [%s]\n", err, strerror(err), errname(err));
} while (argv[++n]);
return 0;