summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-01-04 16:14:51 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2023-01-04 16:41:14 -0800
commit3a21b9b19034b09c704db66ba35ed1038e739eba (patch)
tree3cef49edd6451658959b73f13cd50541efaa31c5
parent6cd9d17ffebb6e4836b3e8f480da331200d32221 (diff)
downloadtz-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.c4
-rw-r--r--zdump.c11
2 files changed, 11 insertions, 4 deletions
diff --git a/date.c b/date.c
index 5819aa0..b62f04d 100644
--- a/date.c
+++ b/date.c
@@ -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);
}
diff --git a/zdump.c b/zdump.c
index b93910e..0e759d6 100644
--- a/zdump.c
+++ b/zdump.c
@@ -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) {