diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2023-01-04 16:14:51 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2023-01-04 16:41:14 -0800 |
commit | 3a21b9b19034b09c704db66ba35ed1038e739eba (patch) | |
tree | 3cef49edd6451658959b73f13cd50541efaa31c5 | |
parent | 6cd9d17ffebb6e4836b3e8f480da331200d32221 (diff) | |
download | tz-3a21b9b19034b09c704db66ba35ed1038e739eba.tar.gz |
Prefer fprintf+strerror to perror
* date.c (main):
* zdump.c (tzalloc, gmtzinit, main): Improve quality of
diagnostics by using strerror and fprintf with suitable formatting
strings, rather than perror which is less flexible.
-rw-r--r-- | date.c | 4 | ||||
-rw-r--r-- | zdump.c | 11 |
2 files changed, 11 insertions, 4 deletions
@@ -86,7 +86,9 @@ main(const int argc, char *argv[]) else if (! (TIME_T_MIN <= secs && secs <= TIME_T_MAX)) errno = ERANGE; if (errno) { - perror(optarg); + char const *e = strerror(errno); + fprintf(stderr, _("date: %s: %s\n"), + optarg, e); errensure(); exit(retval); } @@ -253,7 +253,8 @@ tzalloc(char const *val) { # if HAVE_SETENV if (setenv("TZ", val, 1) != 0) { - perror("setenv"); + char const *e = strerror(errno); + fprintf(stderr, _("%s: setenv: %s\n"), progname, e); exit(EXIT_FAILURE); } tzset(); @@ -332,7 +333,9 @@ gmtzinit(void) static char const gmt0[] = "GMT0"; gmtz = tzalloc(gmt0); if (!gmtz) { - perror(gmt0); + char const *e = strerror(errno); + fprintf(stderr, _("%s: unknown timezone '%s': %s\n"), + progname, gmt0, e); exit(EXIT_FAILURE); } } @@ -597,7 +600,9 @@ main(int argc, char *argv[]) struct tm tm, newtm; bool tm_ok; if (!tz) { - perror(argv[i]); + char const *e = strerror(errno); + fprintf(stderr, _("%s: unknown timezone '%s': %s\n"), + progname, argv[1], e); return EXIT_FAILURE; } if (now) { |