commit: bc8d1c2d2888e0c6d4b9b3e585ae04011e2dd5a5
parent b413fa26a34b0aed147568d9f96fcce4186ef0f9
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 11 Feb 2022 20:36:02 +0100
bin/date: Handle error from time(3)
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/bin/date.c b/bin/date.c
@@ -14,7 +14,7 @@ main(int argc, char *argv[])
{
char outstr[BUFSIZ];
struct tm *tm;
- time_t now = time(NULL);
+ time_t now;
char *format = "%c";
int uflag = 0;
int c;
@@ -29,6 +29,13 @@ main(int argc, char *argv[])
}
}
+ now = time(NULL);
+ if(now == (time_t)-1)
+ {
+ perror("time");
+ exit(EXIT_FAILURE);
+ }
+
if(uflag)
{
tm = gmtime(&now);