Home | History | Annotate | Download | only in include
History log of /src/include/time.h
RevisionDateAuthorComments
 1.56  21-Apr-2025  nia libc: C23: add timespec_getres(3) function

timespec_getres is to timespec_get as clock_getres is to clock_gettime.

PR standards/58608
PR lib/59140
 1.55  21-Apr-2025  nia libc: C23: Add TIME_MONOTONIC as a base for timespec_get

PR standards/58608
 1.54  21-Apr-2025  nia libc: Expose timegm to standard C23 applications.
 1.53  16-Sep-2024  kre The prototype for localtime_r needs to be inside the
#ifndef __LIBC12_SOURCE__ block, as it has a time_t
parameter, and the compat code needs to be able to
make that 32 bits instead of 64.
 1.52  16-Sep-2024  christos move gmtime_r in the right ifdefs block, it was not removed in 202405.
 1.51  16-Sep-2024  christos asctime_r and ctime_r are no more for POSIX202405
 1.50  08-Sep-2024  rillig include: C11 has been released
 1.49  19-Aug-2023  rillig time.h: fix typo in comment
 1.48  23-Oct-2022  jschauma correct tm_sec range to be [0-60]

The previous range introduced in time.h rev1.14 was supposed to account
for a mystical "double leap second", which ultimately never could exist
and was a mistaken interpretation from an early ISO C standard whereby
the possibility of two leap seconds within a year was erroneously
interpreted to mean that two leap seconds could occur at once.
 1.47  04-Oct-2016  kamil Add timespec_get(3) in <time.h> and enable unconditionally struct timespec

These changes conforms to the C11 standard
References:
- 7.27.1/3 Components of time (struct timespec)
- 7.27.2.5 The timespec_get function

According to ISO/IEC 9899:201x (draft) <time.h> defines the timespec
structure and declares the timespec_get(3) function with TIME_UTC
definition.

According to a C++17 standard draft <ctime> offers the same interface in
the std:: namespace.

The timespec_get function modifies the timespec object pointed by ts
to hold the current calendar time in the given base. The standard notes
only the TIME_UTC base with implementation defined value, set it to 1
as zero is reserved for error handling. Once operation was successful this
function returns passed base, otherwise exits with zero.

The timespec struct was already part of the POSIX standard in <time.h>.

Enable this interface unconditionally in the header to allow to use it
in a code prior C11 and C++17 as an extension.

Review notes from <christos>
 1.46  23-Apr-2016  christos branches: 1.46.2;
add clock_cpugetclockid{2,}
 1.45  29-Oct-2015  christos add tzgetgmtoff
 1.44  07-Oct-2014  christos sync function signatures with tzcode
 1.43  21-Apr-2013  joerg strftime_l is part of POSIX2008.
 1.42  21-Apr-2013  joerg Store time-specific locale data directly in the locale.
Ad dstrftime_l, strftime_lz and strptime_l.
 1.41  02-Oct-2012  christos add clock_nanosleep
 1.40  16-Dec-2010  christos branches: 1.40.6; 1.40.12;
Provide a re-entrant and thread-safe set of timezone API's that
don't require locking and can operate on user-specified timezones
as opposed to having to alter the environment to change a timezone.
This work was presented to the tzcode folks and it was generally
accepted, but there seems to be a lot of inertia.
 1.39  14-May-2009  ginsbach Add the getdate(3) function and getdate_err value, conforming to IEEE
Std 1003.1 (``POSIX.1'') and the Open Group Base Specifications X/Open
System Interfaces extension (``XSI'').
 1.38  11-Jan-2009  christos merge christos-time_t
 1.37  21-Sep-2008  christos branches: 1.37.6;
add missing attributes to the remaining calls, even the ones that gcc has
builtin attributes for (for symmetry and consistency). In the future this
might change to use compiler-neutral macros. On the other hand I don't
know of any other compiler that provides other macros with similar
functionality, so why bother?
 1.36  01-Apr-2008  drochner everyone else assumes that defining "_XOPEN_SOURCE" means XPG4.2,
so remove comparisions against the numerical values "3" or "4"
 1.35  13-Sep-2005  christos compat code reorg
 1.34  03-Feb-2005  perry de-__P -- the hack is long since useless. Discussed with christos,
matt, kleink, others. Approved by christos.
 1.33  21-Dec-2003  kleink Do a little const cleanup, for consistency with std interfaces.
 1.32  13-Sep-2003  kleink Sprinkle restrict into timer_{create,settime}(2).
 1.31  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22270, verified by myself.
 1.30  28-Apr-2003  bjh21 Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.

This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.

I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.

Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
 1.29  30-Jun-2002  bjh21 Version times() so that programs compiled before the recent change to make
sysconf(_SC_CLK_TCK) return hz will work.

In detail:
__times13() returns values scaled by hz.
times() returns values scaled by 100.
<sys/times.h> renames times() to __times13().

_SC_CLK_TCK has changed from 3 to 39.
sysconf(3) returns 100.
sysconf(39) returns hz.
CLK_TCK is defined as sysconf(39).
 1.28  23-Jun-2002  perry In the manner of Solaris and other OSes, we now define CLK_TCK to
expand to a call to __sysconf(_SC_CLK_TCK), rather than hard coding it
as a constant.
 1.27  31-Mar-2001  kleink Finally deprecate the old timezone() interface in favor of an XSH5
timezone/daytime pair; as proposed by J.T. in September, 1996.
Fixes PR standards/11807 by Nick Hudson.
 1.26  29-Mar-2001  kleink Sprinkle some restrict.
 1.25  06-Jul-2000  hubertf branches: 1.25.2;
Fix typo in comment: CUT -> UTC
 1.24  10-Jan-2000  kleink branches: 1.24.4;
Move <null.h> to <sys/null.h> for the purpose of avoiding conflicts due to
std C headers including it, and a kernel module written in C++ would benfit
as well.
 1.23  22-Dec-1999  kleink For the benefit of G++'s null pointer constant implementation, #define NULL
as __null with egcs 1.0 (GCC 2.90) and above. As several headers are affected
by this change, move the definition into a new header file, <null.h>, to ease
maintenance.
 1.22  15-Sep-1998  kleink Remove the public declaration of gtime(), which is shipped with tzcode but is
not compiled into our libc since it is intended for use with Mach only.
 1.21  10-Sep-1998  kleink Declare asctime_r(), ctime_r(), gmtime_r() and localtime_r(), and rearrange
name space protection a bit.
 1.20  27-Jul-1998  mycroft Slight rearrangement.
 1.19  27-Jul-1998  mycroft Need cdefs.h.
 1.18  27-Jul-1998  mycroft Make many of the new consts dependent on a new `__AUDIT__' flag, to avoid
breaking third party software. *sigh*
 1.17  26-Jul-1998  mycroft const poisoning.
 1.16  26-Jul-1998  mycroft const poisoning.
 1.15  02-Feb-1998  perry merge lite-2
 1.14  02-Nov-1997  kleink * Move prototypes of clock_getres(), clock_gettime() and clock_settime() from
<sys/time.h> to this file.
* Update range comment wrt. the tm_sec member of struct tm to [0-61] (double
leap seconds are supported).
 1.13  04-Oct-1997  kleink branches: 1.13.2;
Per 1003.1b-93, move nanosleep() prototype from <sys/time.h> to <time.h>
and add appropriate namespace protection. Also protect timer_*() prototypes.
 1.12  13-Jul-1997  christos Add typedefs for clockid_t and timer_t
 1.11  13-Jul-1997  christos - Added prototypes for non POSIX that are marked STD inspired:
offtime, timelocal, timegm, timeoff, gtime, time2posix, posix2time.
- Added prototypes for the currently stubbed out timer functions:
timer_{create,delete,getoverrun,gettime,settime}
 1.10  26-May-1997  kleink Add strptime(3) prototype.
 1.9  26-Oct-1994  cgd new RCS ID format.
 1.8  21-May-1994  cgd add _BSD's to ansi types
 1.7  16-May-1994  cgd update all but ctype.h, dumprestore.h, time.h to 4.4-Lite versions.
USL copyright additions on those. Kill varargs.h, because it can simply
be a link to the machine-dependent version.
 1.6  20-Jan-1994  jtc Declare tzname[] extern, so compiler won't include it in object files.
 1.5  11-Oct-1993  jtc declare char *tzname[2];
 1.4  18-Aug-1993  jtc As per Chris Torek's suggestion, define CLOCKS_PER_SEC and CLK_TCK to 100.
When we get sysconf, we can define them in terms of the kernel's notion of
interrupts per second if we so choose. Until then, the constant value
seems to satisfy the requirements presented by ISO C and POSIX, even if it
may lie about the true number of clocks per second.
 1.3  17-Aug-1993  jtc Define CLOCKS_PER_SEC.
 1.2  01-Aug-1993  mycroft Add RCS identifiers.
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2  02-Feb-1998  perry import lite-2
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.2.1  28-Sep-1998  cgd pull up rev 1.22 (remove gtime declaration) from trunk (kleink).
 1.24.4.1  18-Jul-2000  hubertf Pull up rev. 1.25 into 1.5 branch, OK'd by thorpej:

Fix typo in comment: CUT -> UTC
 1.25.2.2  01-Aug-2002  nathanw Catch up to -current.
 1.25.2.1  08-Apr-2001  nathanw Merge trunk onto branch.
 1.37.6.4  10-Nov-2008  christos version tzset{,wall}
 1.37.6.3  08-Nov-2008  christos delete redundant declaration of time()
 1.37.6.2  08-Nov-2008  christos changes for 64 bit time_t
 1.37.6.1  21-Sep-2008  christos file time.h was added on branch christos-time_t on 2008-11-08 21:13:13 +0000
 1.40.12.2  23-Jun-2013  tls resync from head
 1.40.12.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.40.6.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.40.6.1  30-Oct-2012  yamt sync with head
 1.46.2.1  04-Nov-2016  pgoyette Sync with HEAD

RSS XML Feed