Re: POSIX.1-2024 requires 64-bit time_t

Mark Harris
2025-05-18T22:09:21Z

On Sun, May 18, 2025 at 3:06 PM Alejandro Colomar <alx@kernel.org> wrote:
>
> Hi Mark,
>
> On Sun, May 18, 2025 at 02:52:30PM -0700, Mark Harris wrote:
> > For glibc, all 64-bit platforms, and the most recently added 32-bit
> > platforms (arc, riscv32, or1k), use 64-bit time_t. All older but
> > still-supported 32-bit platforms (arm, csky, hppa, m68k, microblaze,
> > mips, powerpc, s390, sh, sparc, x86) currently use 32-bit time_t by
> > default but can use 64-bit time_t with -D_TIME_BITS=64. For musl, all
> > platforms use 64-bit time_t.
>
> Thanks!
>
> > POSIX.1-2024 requires that an implementation offer a conforming
> > environment that supports 64-bit time_t, but it is also free to offer
> > other non-conforming environments that use 32-bit time_t.
>
> Are you sure? That's not what I read from the standard.
>
> POSIX.1-2024 says something like that for other types; for example:
>
> The implementation shall support one or more programming
> environments in which the widths of blksize_t, pid_t, size_t,
> ssize_t, and suseconds_t are no greater than the width of type
> long.
>
> But for time_t it is very strict:
>
> time_t shall be an integer type with a width (see <stdint.h>) of
> at least 64 bits.
>
> It doesn't seem to support such alternate environments for time_t. Of
> course, an implementation is free to not conform, but then it's a non-
> conforming implementation.
>
>
> Have a lovely night!
> Alex
>
> --
> <https://www.alejandro-colomar.es/>

https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/unistd.h.html

"Implementations may support multiple programming environments with
some of them conforming to this standard and some not conforming. The
_POSIX_Vn_ILP* and _POSIX_Vn_LP* constants, and corresponding
sysconf() and getconf calls, only indicate whether each programming
environment is supported; they do not indicate anything about
conformance of the environments that are supported. For example, an
implementation may support the ILP32_OFF32 environment for legacy
reasons with a 32-bit time_t, whereas in a conforming environment
time_t is required to have a width of at least 64 bits. Application
writers should consult an implementation's POSIX Conformance Document
for information about the conformance of each supported programming
environment."

- Mark