Scroll to navigation

timespec(3type) timespec(3type)

NAME

timespec - time in seconds and nanoseconds

LIBRARY

Standard C library (libc)

SYNOPSIS

#include <time.h>
struct timespec {
    time_t  tv_sec;   /* Seconds */
    long    tv_usec;  /* Nanoseconds [0, 999999999] */
};

DESCRIPTION

Describes times in seconds and nanoseconds.

STANDARDS

C11 and later; POSIX.1-2001 and later.

NOTES

The following headers also provide this type: <aio.h>, <mqueue.h>, <sched.h>, <signal.h>, <sys/select.h>, and <sys/stat.h>.

BUGS

Under glibc, tv_nsec is the syscall long, though this affects only fringe architectures like X32, which is ILP32, but uses the LP64 AMD64 syscall ABI. In reality, the field ends up being defined as:


#if __x86_64__ && __ILP32__  /* == x32 */

long long tv_nsec; #else
long tv_nsec; #endif

This is a long-standing and long-enshrined glibc bug #16437, and an incompatible extension to the standards; however, as even a 32-bit long can hold the entire tv_nsec range, it's always safe to forcibly down-cast it to the standard type.

SEE ALSO

clock_gettime(2), clock_nanosleep(2), nanosleep(2), timerfd_gettime(2), timer_gettime(2), time_t(3type), timeval(3type)

2022-10-30 Linux man-pages 6.02