Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle various time_t sizes in printf and scanf #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

snogge
Copy link
Contributor

@snogge snogge commented Apr 15, 2024

The members of the timeval struct are both signed (defined by POSIX) and typically both 64 bits on a system where time_t is 64 bits. This is possible also on 32 bit systems where time_t is larger to handle the 2038 problem.

It's practically impossible to find a type and printf format that works even on all glibc systems. Play it safe and always use printf with intmax_t and explict int64_t variables for scanf.

Alternatively, we could use autoconf to figure out the sizes and printf format specifiers, but that seemed way to complicated for what we would gain.

Note that I've changes some prints from unsigned to signed, but the data types were always signed anyway and any negative values would probably have resulted in some odd-looking timestamps.

The members of the timeval struct are both signed (defined by POSIX)
and typically both 64 bits on a system where time_t is 64 bits.  This
is possible also on 32 bit systems where time_t is larger to handle
the 2038 problem.

It's practically impossible to find a type and printf format that
works even on all glibc systems.  Play it safe and always use printf
with intmax_t and explict int64_t variables for scanf.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant