From bdcbf8589716c047a732db3cc349ee6114ccc25f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 7 May 2023 12:39:26 +0200 Subject: iterate on previous commit which adds $SFEED_NEW_MAX_SECS Separate the common pattern to get the time to compare new items in format tools to the new util function: getcomparetime(). Some changes and notes: - Change it so it is OK to set this value to 0 or negative (in the future). - sfeed_curses: truncating newmaxsecs to an int would limit the value too much. - Just use strtotime() and parse the value to time_t. This is a signed long (32-bit, until 2038) or signed long long (64-bit) on most platforms. - sfeed_curses gets the comparison time on reload aswell and it needs errno = 0, because it uses die(). time() is not guaranteed to set an errno if it fails. - Rename environment variable to $SFEED_NEW_AGE. --- sfeed_frames.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'sfeed_frames.c') diff --git a/sfeed_frames.c b/sfeed_frames.c index e52abd1..b2f75cf 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -77,9 +77,8 @@ int main(int argc, char *argv[]) { FILE *fpindex, *fpitems, *fpmenu = NULL, *fp; - char *name, *tmp, *endptr; + char *name; int i, showsidebar = (argc > 1); - long l; struct feed *f; if (pledge("stdio rpath wpath cpath", NULL) == -1) @@ -88,18 +87,8 @@ main(int argc, char *argv[]) if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); /* write main index page */ if (!(fpindex = fopen("index.html", "wb"))) -- cgit v1.2.3