From d425b524f5ce06e6d9cbb6838c4bf8b66b73ee06 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 5 Jul 2020 15:53:37 +0200 Subject: sfeed_atom: the updated field is mandatory: use the current time... ... if it is missing/invalid. --- sfeed_atom.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sfeed_atom.c b/sfeed_atom.c index c5ea737..0463ef7 100644 --- a/sfeed_atom.c +++ b/sfeed_atom.c @@ -7,6 +7,7 @@ #include "util.h" +static struct tm tmnow; static time_t now; static char *line; static size_t linesize; @@ -38,7 +39,7 @@ static void printfeed(FILE *fp, const char *feedname) { char *fields[FieldLast]; - struct tm *tm; + struct tm tmitem, *tm; time_t parsedtime; ssize_t linelen; @@ -74,12 +75,12 @@ printfeed(FILE *fp, const char *feedname) } parsedtime = 0; - if (!strtotime(fields[FieldUnixTimestamp], &parsedtime) && - (tm = gmtime(&parsedtime))) { - fprintf(stdout, "\t%04d-%02d-%02dT%02d:%02d:%02dZ\n", - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); - } + if (strtotime(fields[FieldUnixTimestamp], &parsedtime) || + !(tm = gmtime_r(&parsedtime, &tmitem))) + tm = &tmnow; + fprintf(stdout, "\t%04d-%02d-%02dT%02d:%02d:%02dZ\n", + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); if (fields[FieldAuthor][0]) { fputs("\t", stdout); @@ -120,8 +121,8 @@ main(int argc, char *argv[]) if ((now = time(NULL)) == -1) err(1, "time"); - if (!(tm = gmtime(&now))) - err(1, "gmtime"); + if (!(tm = gmtime_r(&now, &tmnow))) + err(1, "gmtime_r"); fputs("\n" "\n" -- cgit v1.2.3