sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 785a50c37c11c8e92387f8409d91bd77c41297b2
parent a335239b1f9803298e42e16535d759856be831b0
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 15 Mar 2020 23:13:31 +0100

sfeed_mbox: time parsing and consistency fixes

- make converting time error out as the other format tools do also.
- remove wrong comment.
- make code-style consistent.

Diffstat:
Msfeed_mbox.c | 16+++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/sfeed_mbox.c b/sfeed_mbox.c @@ -24,8 +24,8 @@ djb2(unsigned char *s, unsigned long hash) static void printfeed(FILE *fp, const char *feedname) { - struct tm tm; char *fields[FieldLast], timebuf[32]; + struct tm *tm; time_t parsedtime; unsigned long hash; ssize_t linelen; @@ -36,20 +36,18 @@ printfeed(FILE *fp, const char *feedname) hash = djb2((unsigned char *)line, 5381UL); if (!parseline(line, fields)) break; + parsedtime = 0; if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) continue; + if (!(tm = gmtime(&parsedtime))) + err(1, "gmtime"); + if (!strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S +0000", tm)) + errx(1, "strftime"); /* mbox + mail header */ printf("From MAILER-DAEMON %s\n", mtimebuf); - /* can't convert: default to formatted time for time_t 0. */ - if (gmtime_r(&parsedtime, &tm) && - strftime(timebuf, sizeof(timebuf), - "%a, %d %b %Y %H:%M:%S +0000", &tm)) - printf("Date: %s\n", timebuf); - else - printf("Date: Thu, 01 Jan 1970 00:00:00 +0000\n"); - + printf("Date: %s\n", timebuf); printf("From: %s <sfeed@>\n", fields[FieldAuthor][0] ? fields[FieldAuthor] : "unknown"); printf("To: %s <%s@%s>\n", user, user, host); if (feedname[0])