|
Message-Id: <59f95d06c1294c74217358bda83757b61740bda4.1684932978.git.Jens.Gustedt@inria.fr> Date: Fri, 26 May 2023 11:35:51 +0200 From: Jens Gustedt <Jens.Gustedt@...ia.fr> To: musl@...ts.openwall.com Subject: [C23 time 1/1] C23: add timespec_getres and deprecate asctime and ctime The identifier timespec_getres was not reserved before so we have to protect it against includes by older C versions and make the symbol weak, so it doesn't conflict with potential user code. The implementation just uses clock_getres underneath, which forces that function also to be weak such that we don't link with that symbol accidentally in pure C mode. Deprecate asctime and ctime. These are also deprecated by POSIX, so there should not be a conflict between the two standards. Also, use the __STDC_VERSION_TIME_H__ macro, this still have to be adapted to the final value that will be decided by WG14 for __STDC_VERSION__. --- include/time.h | 9 +++++---- src/time/clock_getres.c | 4 +++- src/time/timespec_getres.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/time/timespec_getres.c diff --git a/include/time.h b/include/time.h index e94b3a01..074a64e1 100644 --- a/include/time.h +++ b/include/time.h @@ -1,5 +1,5 @@ -#ifndef _TIME_H -#define _TIME_H +#ifndef __STDC_VERSION_TIME_H__ +#define __STDC_VERSION_TIME_H__ 202300L #ifdef __cplusplus extern "C" { @@ -58,8 +58,8 @@ time_t mktime (struct tm *); size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); struct tm *gmtime (const time_t *); struct tm *localtime (const time_t *); -char *asctime (const struct tm *); -char *ctime (const time_t *); +__deprecated char *asctime(const struct tm *); +__deprecated char *ctime(const time_t *); int timespec_get(struct timespec *, int); #define CLOCKS_PER_SEC 1000000L @@ -69,6 +69,7 @@ int timespec_get(struct timespec *, int); struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); time_t timegm(struct tm *); +int timespec_getres(struct timespec *, int); #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ diff --git a/src/time/clock_getres.c b/src/time/clock_getres.c index 81c67037..248e6d18 100644 --- a/src/time/clock_getres.c +++ b/src/time/clock_getres.c @@ -1,7 +1,7 @@ #include <time.h> #include "syscall.h" -int clock_getres(clockid_t clk, struct timespec *ts) +int __clock_getres(clockid_t clk, struct timespec *ts) { #ifdef SYS_clock_getres_time64 /* On a 32-bit arch, use the old syscall if it exists. */ @@ -19,3 +19,5 @@ int clock_getres(clockid_t clk, struct timespec *ts) * 32-bit arch and we can get result directly into timespec. */ return syscall(SYS_clock_getres, clk, ts); } + +weak_alias(__clock_getres, clock_getres); diff --git a/src/time/timespec_getres.c b/src/time/timespec_getres.c new file mode 100644 index 00000000..6ecbbdc4 --- /dev/null +++ b/src/time/timespec_getres.c @@ -0,0 +1,12 @@ +#include <time.h> + +extern int __clock_getres(clockid_t clk, struct timespec *ts); + +/* There is no other implemented value than TIME_UTC; all other values + * are considered erroneous. */ +int timespec_getres(struct timespec * ts, int base) +{ + if (base != TIME_UTC) return 0; + int ret = __clock_getres(CLOCK_REALTIME, ts); + return ret < 0 ? 0 : base; +} -- 2.34.1
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.