From ed511efbea44b627752d044cc65256b0591c0ae7 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 15 Jul 2019 11:49:12 -0400 Subject: add symbolic error name to output --- strerror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 #include #include +#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; -- cgit v1.2.1