summaryrefslogtreecommitdiff
path: root/sfeed_mbox.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2022-03-14 13:25:52 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2022-03-14 13:25:52 +0100
commitb6f7a3fe15f2f253a1653454f514b467aa20f821 (patch)
treec0fdddaa251dbb0a4da66a86b547032bb84d3bc8 /sfeed_mbox.c
parent3dbdf1ccfa5f109f8d7489f913ed57aa8e9b5f11 (diff)
improve time(NULL) error checking
Use errx, time(NULL) does not set errno. For sfeed_curses reset errno so it doesn't print a random error if it failed. POSIX recommends checking against (time_t)-1 on failure. Note that some implementation, like the OpenBSD man page says time() cannot fail.
Diffstat (limited to 'sfeed_mbox.c')
-rw-r--r--sfeed_mbox.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sfeed_mbox.c b/sfeed_mbox.c
index 6419d16..c2827d4 100644
--- a/sfeed_mbox.c
+++ b/sfeed_mbox.c
@@ -152,8 +152,8 @@ main(int argc, char *argv[])
user = "you";
if (gethostname(host, sizeof(host)) == -1)
err(1, "gethostname");
- if ((now = time(NULL)) == -1)
- err(1, "time");
+ if ((now = time(NULL)) == (time_t)-1)
+ errx(1, "time");
if (!gmtime_r(&now, &tmnow))
err(1, "gmtime_r: can't get current time");
if (!strftime(mtimebuf, sizeof(mtimebuf), "%a %b %d %H:%M:%S %Y", &tmnow))