From b01b3bc1af807bda4121efff37a05049da35e81f Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 5 Aug 2019 10:50:33 -0400 Subject: simplify diagnostics --- cat.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/cat.c b/cat.c index ef977aa..b9c45cf 100644 --- a/cat.c +++ b/cat.c @@ -24,7 +24,7 @@ #define _XOPEN_SOURCE 700 #include -#include +#include #include #include #include @@ -38,13 +38,7 @@ static int cat(const char *path) } if (f == NULL) { - static char *fmt = NULL; - const char *def = "cat: %s: %s\n"; - if (fmt == NULL) { - nl_catd catd = catopen("cat", NL_CAT_LOCALE); - fmt = catgets(catd, NL_SETD, 1, def); - } - fprintf(stderr, fmt, path ? path : "stdin", strerror(errno)); + fprintf(stderr, "cat: %s: %s\n", path, strerror(errno)); return 1; } @@ -62,25 +56,23 @@ static int cat(const char *path) int main(int argc, char *argv[]) { - int ret = 0, c = 0; + setlocale(LC_ALL, ""); + int c; while ((c = getopt(argc, argv, "u")) != -1) { switch(c) { case 'u': /** Do not buffer output **/ setbuf(stdout, NULL); break; + default: return 1; } } + int ret = 0; do { ret |= cat(argv[optind++]); } while (optind < argc); - return ret; } - -/**cat en_US@color -1 \033[31mcat: Couldn't open \033[0;41;23m%s\033[0;31m: %s\033[0m\n -**/ -- cgit v1.2.1