| 1 |
'\" t |
| 2 |
.\" SPDX-License-Identifier: 0BSD |
| 3 |
.\" |
| 4 |
.TH timespec_get 3 2025-02-10 "Linux man-pages 6.13" |
| 5 |
.SH NAME |
| 6 |
timespec_get, |
| 7 |
timespec_getres |
| 8 |
\- |
| 9 |
ISO C interface to clock and time functions |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ), |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <time.h> |
| 16 |
.P |
| 17 |
.BI "int timespec_get(struct timespec *" res ", int " base ); |
| 18 |
.BI "int timespec_getres(struct timespec *" tp ", int " base ); |
| 19 |
.fi |
| 20 |
.SH DESCRIPTION |
| 21 |
The |
| 22 |
.BR timespec_get () |
| 23 |
function stores the current time, based on the specified time base, in the |
| 24 |
.BR timespec (3type) |
| 25 |
structure pointed to by |
| 26 |
.IR res . |
| 27 |
.P |
| 28 |
The |
| 29 |
.BR timespec_getres () |
| 30 |
function stores the resolution of times retrieved by |
| 31 |
.BR timespec_get () |
| 32 |
with the specified time base in the |
| 33 |
.BR timespec (3type) |
| 34 |
structure pointed to by |
| 35 |
.IR tp , |
| 36 |
if |
| 37 |
.I tp |
| 38 |
is non-NULL. |
| 39 |
For a particular time base, |
| 40 |
the resolution is constant for the lifetime of the calling process. |
| 41 |
.P |
| 42 |
.B TIME_UTC |
| 43 |
is always a supported time base, |
| 44 |
and is the only time base supported on Linux. |
| 45 |
The time and resolution in this time base |
| 46 |
are the same as those retrieved by |
| 47 |
.I clock_gettime(CLOCK_REALTIME,\~res) |
| 48 |
and |
| 49 |
.IR clock_getres(CLOCK_REALTIME,\~tp) , |
| 50 |
respectively. |
| 51 |
Other systems may support additional time bases. |
| 52 |
.SH RETURN VALUE |
| 53 |
.BR timespec_get () |
| 54 |
returns the nonzero |
| 55 |
.I base |
| 56 |
if it is a supported time base |
| 57 |
and the current time was successfully retrieved, or 0 otherwise. |
| 58 |
.P |
| 59 |
.BR timespec_getres () |
| 60 |
returns the nonzero |
| 61 |
.I base |
| 62 |
if it is a supported time base, or 0 otherwise. |
| 63 |
.SH ATTRIBUTES |
| 64 |
For an explanation of the terms used in this section, see |
| 65 |
.BR attributes (7). |
| 66 |
.TS |
| 67 |
allbox; |
| 68 |
lbx lb lb |
| 69 |
l l l. |
| 70 |
Interface Attribute Value |
| 71 |
T{ |
| 72 |
.na |
| 73 |
.nh |
| 74 |
.BR timespec_get (), |
| 75 |
.BR timespec_getres () |
| 76 |
T} Thread safety MT-Safe |
| 77 |
.TE |
| 78 |
.SH STANDARDS |
| 79 |
.TP |
| 80 |
.BR timespec_get () |
| 81 |
.TQ |
| 82 |
.B TIME_UTC |
| 83 |
C23 (though ISO C doesn't specify the time epoch), |
| 84 |
POSIX.1-2024. |
| 85 |
.TP |
| 86 |
.BR timespec_getres () |
| 87 |
C23. |
| 88 |
.SH HISTORY |
| 89 |
.TP |
| 90 |
.BR timespec_get () |
| 91 |
.TQ |
| 92 |
.B TIME_UTC |
| 93 |
C11, POSIX.1-2024, glibc 2.16, musl 1.1.10. |
| 94 |
.TP |
| 95 |
.BR timespec_getres () |
| 96 |
C23, glibc 2.34. |
| 97 |
.SH SEE ALSO |
| 98 |
.BR clock_gettime (2), |
| 99 |
.BR clock_getres (2) |