From: claudio Date: Thu, 23 Jun 2022 12:40:32 +0000 (+0000) Subject: fmt_timeframe() cleanup. Remove the ring buffer, it is not required. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=81dd5016dc730554a42746b2b8e718b0f0c5426a;p=openbsd fmt_timeframe() cleanup. Remove the ring buffer, it is not required. Ensure that the time_t is positive and print increadibly long timeframes of over 19 years just as weeks. OK tb@ --- diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index 319c0b29f96..9c50ab647f5 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.277 2022/06/15 10:10:50 claudio Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.278 2022/06/23 12:40:32 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -575,22 +575,17 @@ fmt_auth_method(enum auth_method method) } } -#define TF_BUFS 8 -#define TF_LEN 9 +#define TF_LEN 16 const char * fmt_timeframe(time_t t) { - char *buf; - static char tfbuf[TF_BUFS][TF_LEN]; /* ring buffer */ - static int idx = 0; + static char buf[TF_LEN]; unsigned int sec, min, hrs, day; - unsigned long long week; - - buf = tfbuf[idx++]; - if (idx == TF_BUFS) - idx = 0; + unsigned long long week; + if (t < 0) + t = 0; week = t; sec = week % 60; @@ -602,7 +597,9 @@ fmt_timeframe(time_t t) day = week % 7; week /= 7; - if (week > 0) + if (week >= 1000) + snprintf(buf, TF_LEN, "%02lluw", week); + else if (week > 0) snprintf(buf, TF_LEN, "%02lluw%01ud%02uh", week, day, hrs); else if (day > 0) snprintf(buf, TF_LEN, "%01ud%02uh%02um", day, hrs, min);