Re: [PATCH 20/26] xfs_db: report bigtime format timestamps

Darrick J. Wong
2020-10-29T17:46:00Z

On Thu, Oct 29, 2020 at 09:50:10AM +0000, Christoph Hellwig wrote:
> > +static void
> > +fp_time64(
> > + time64_t sec)
> > {
> > + time_t tt = sec;
> > char *c;
> > +
> > + BUILD_BUG_ON(sizeof(long) != sizeof(time_t));
>
> Why?

Trying to make the best of a braindead situation. IIRC C99/11/18 don't
provide a specific definition of what time_t is supposed to be. POSIX
2017 seems to hint that it should be an integer seconds counter, but
doesn't provide any further clarity. (And then says it defers to ISO C,
having made that allusion to integerness.)

Since I'd rather print a raw s64 value than risk truncating a time and
printing a totally garbage prettyprinted timestamp, I added the
LONG_{MIN,MAX} checks, but that assumes that time_t is a long.

Hence adding a trap so that if xfsprogs ever does encounter C library
where time_t isn't a long int, we'd get to hear about it. Granted that
further assumes that time_t isn't a float, but ... ugh.

I guess this could have assigned sec to a time_t value and then compared
it back to the original value to see if we ripped off any upper bits.

--D