Download raw body.
drop a useless function
On 2025-04-08 10:21 +02, Jan Stary <hans@stare.cz> wrote:
> On Apr 08 09:09:07, florian@openbsd.org wrote:
>> the comment right above it should go as well.
>>
>> On 2025-04-07 21:20 +02, Jan Stary <hans@stare.cz> wrote:
>> > The tformat() function in zdump.c
>> > merely returns a constant string
>> > and is called once.
>
> Thanks for checking the diff.
>
> I left that in, thinking it applies to all "code below"
> i.e. also dumptime(), being the tail of zdump.c - but
> perhaps it's just the "%lld" that was meant by then.
>
no, it came in with rev 1.16 of lib/libc/time/zdump.c which introduced
tformat(). It did some unsavoury things. dumptime() was already there at
the time.
@@ -375,6 +587,33 @@ struct tm * tmp;
return (result == NULL) ? &nada : result;
}
+/*
+** The code below can fail on certain theoretical systems;
+** it works on all known real-world systems as of 2004-12-30.
+*/
+
+static const char *
+tformat()
+{
+ if (0.5 == (time_t) 0.5) { /* floating */
+ if (sizeof (time_t) > sizeof (double))
+ return "%Lg";
+ return "%g";
+ }
+ if (0 > (time_t) -1) { /* signed */
+ if (sizeof (time_t) > sizeof (long))
+ return "%lld";
+ if (sizeof (time_t) > sizeof (int))
+ return "%ld";
+ return "%d";
+ }
+ if (sizeof (time_t) > sizeof (unsigned long))
+ return "%llu";
+ if (sizeof (time_t) > sizeof (unsigned int))
+ return "%lu";
+ return "%u";
+}
+
static void
dumptime(timeptr)
register const struct tm * timeptr;
@@ -388,7 +627,13 @@ register const struct tm * timeptr;
> (And perhaps a comment making a statement about
> "all known systems as of 2004" should go at any rate :-)
>
> Updated diff below.
OK florian for after release or I'll take OKs to commit it myself.
>
> Jan
>
> Index: zdump.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/zdump/zdump.c,v
> diff -u -p -r1.14 zdump.c
> --- zdump.c 15 Mar 2016 19:50:48 -0000 1.14
> +++ zdump.c 8 Apr 2025 08:19:27 -0000
> @@ -62,7 +62,6 @@ static void dumptime(const struct tm *t
> static time_t hunt(char *name, time_t lot, time_t hit);
> static void setabsolutes(void);
> static void show(char *zone, time_t t, int v);
> -static const char *tformat(void);
> static time_t yeartot(long y);
> static void usage(void);
>
> @@ -358,7 +357,7 @@ show(char *zone, time_t t, int v)
> if (v) {
> tmp = gmtime(&t);
> if (tmp == NULL) {
> - printf(tformat(), t);
> + printf("%lld", t);
> } else {
> dumptime(tmp);
> printf(" UTC");
> @@ -392,17 +391,6 @@ abbr(struct tm *tmp)
> return &nada;
> result = tzname[tmp->tm_isdst];
> return (result == NULL) ? &nada : result;
> -}
> -
> -/*
> -** The code below can fail on certain theoretical systems;
> -** it works on all known real-world systems as of 2004-12-30.
> -*/
> -
> -static const char *
> -tformat(void)
> -{
> - return "%lld";
> }
>
> static void
>
--
In my defence, I have been left unsupervised.
drop a useless function