diff options
| author | kamil <kamil@NetBSD.org> | 2016-10-04 09:41:40 +0000 |
|---|---|---|
| committer | kamil <kamil@NetBSD.org> | 2016-10-04 09:41:40 +0000 |
| commit | 524e98c2b0788d904a1ce08e91a4bdb07f53d0cb (patch) | |
| tree | 0429518d8097dc83510cb9bc65b590c115090381 /include/time.h | |
| parent | f367355dc9836205b41ad18e025b7c2a00b8e250 (diff) | |
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>
Diffstat (limited to 'include/time.h')
| -rw-r--r-- | include/time.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/include/time.h b/include/time.h index 628a1993cc8..f870ebf5750 100644 --- a/include/time.h +++ b/include/time.h @@ -1,4 +1,4 @@ -/* $NetBSD: time.h,v 1.46 2016/04/23 23:10:10 christos Exp $ */ +/* $NetBSD: time.h,v 1.47 2016/10/04 09:41:41 kamil Exp $ */ /* * Copyright (c) 1989, 1993 @@ -137,9 +137,12 @@ struct tm *getdate(const char *); extern int getdate_err; #endif +/* ISO/IEC 9899:201x 7.27.1/3 Components of time */ +#include <sys/timespec.h> + #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ defined(_NETBSD_SOURCE) -#include <sys/time.h> /* XXX for struct timespec */ +#include <sys/time.h> struct sigevent; struct itimerspec; int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); @@ -231,6 +234,10 @@ char *strptime_l(const char * __restrict, const char * __restrict, #endif /* _NETBSD_SOURCE */ +/* ISO/IEC 9899:201x 7.27.2.5 The timespec_get function */ +#define TIME_UTC 1 /* time elapsed since epoch */ +int timespec_get(struct timespec *ts, int base); + __END_DECLS #endif /* !_TIME_H_ */ |
