Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Sam James <sam@gentoo.org>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH v3 4/4] io: Adapt to >= 64-bit time_t
Date: Mon, 18 Dec 2023 21:27:02 -0800	[thread overview]
Message-ID: <20231219052702.GJ361584@frogsfrogsfrogs> (raw)
In-Reply-To: <20231215013657.1995699-4-sam@gentoo.org>

On Fri, Dec 15, 2023 at 01:36:43AM +0000, Sam James wrote:
> We now require (at least) 64-bit time_t, so we need to adjust some printf
> specifiers accordingly.
> 
> Unfortunately, we've stumbled upon a ridiculous C mmoment whereby there's

Plenty of those to go around...

> no neat format specifier (not even one of the inttypes ones) for time_t, so
> we cast to intmax_t and use %jd.
> 
> Signed-off-by: Sam James <sam@gentoo.org>
> ---
> v3: uintmax_t -> intmax_t as time_t is signed
> 
>  io/stat.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/io/stat.c b/io/stat.c
> index e8f68dc3..743a7586 100644
> --- a/io/stat.c
> +++ b/io/stat.c
> @@ -66,11 +66,11 @@ dump_raw_stat(struct stat *st)
>  	printf("stat.ino = %llu\n", (unsigned long long)st->st_ino);
>  	printf("stat.size = %lld\n", (long long)st->st_size);
>  	printf("stat.blocks = %lld\n", (long long)st->st_blocks);
> -	printf("stat.atime.tv_sec = %ld\n", st->st_atim.tv_sec);
> +	printf("stat.atime.tv_sec = %jd\n", (intmax_t)st->st_atim.tv_sec);

I almost wonder if we want a similar
BUILD_BUG_ON(sizeof(time_t) < 8);
here or something?

Also I totally didn't realize that "intmax_t" is actually s64 on x86_64.
I saw "int" and assumed "still 32-bit".

But, I guess C99 says "...capable of representing any value of any basic
signed integer type supported by the implementation."

So it apparently works even for 32-bit compilers, at least according to
godbolt.org...
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D


>  	printf("stat.atime.tv_nsec = %ld\n", st->st_atim.tv_nsec);
> -	printf("stat.ctime.tv_sec = %ld\n", st->st_ctim.tv_sec);
> +	printf("stat.ctime.tv_sec = %jd\n", (intmax_t)st->st_ctim.tv_sec);
>  	printf("stat.ctime.tv_nsec = %ld\n", st->st_ctim.tv_nsec);
> -	printf("stat.mtime.tv_sec = %ld\n", st->st_mtim.tv_sec);
> +	printf("stat.mtime.tv_sec = %jd\n", (intmax_t)st->st_mtim.tv_sec);
>  	printf("stat.mtime.tv_nsec = %ld\n", st->st_mtim.tv_nsec);
>  	printf("stat.rdev_major = %u\n", major(st->st_rdev));
>  	printf("stat.rdev_minor = %u\n", minor(st->st_rdev));
> -- 
> 2.43.0
> 
> 

  reply	other threads:[~2023-12-19  5:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15  1:36 [PATCH v3 1/4] Remove use of LFS64 interfaces Sam James
2023-12-15  1:36 ` [PATCH v3 2/4] io: Assert we have a sensible off_t Sam James
2023-12-19  5:19   ` Darrick J. Wong
2023-12-19  5:54   ` Christoph Hellwig
2023-12-26 20:49     ` Sam James
2024-01-22  4:58       ` Sam James
2024-01-22  6:33         ` Christoph Hellwig
2024-01-22  7:22           ` Sam James
2023-12-15  1:36 ` [PATCH v3 3/4] build: Request 64-bit time_t where possible Sam James
2023-12-19  5:27   ` Darrick J. Wong
2023-12-15  1:36 ` [PATCH v3 4/4] io: Adapt to >= 64-bit time_t Sam James
2023-12-19  5:27   ` Darrick J. Wong [this message]
2023-12-19  5:55 ` [PATCH v3 1/4] Remove use of LFS64 interfaces Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231219052702.GJ361584@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sam@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox