[PATCH 2/5] time: Implement c23 timespec_get base
Florian Weimer
fweimer@redhat.com
Tue Jun 20 12:44:41 GMT 2023
* Yonggang Luo via Libc-alpha:
> diff --git a/time/timespec_get.c b/time/timespec_get.c
> index 9b1d4f22ed..a57b1ee0b8 100644
> --- a/time/timespec_get.c
> +++ b/time/timespec_get.c
> @@ -22,10 +22,52 @@
> int
> timespec_get (struct timespec *ts, int base)
> {
> - if (base == TIME_UTC)
> + clockid_t clockid = -1;
> + switch (base) {
> + default:
> + break;
> + case TIME_UTC:
> + clockid = CLOCK_REALTIME;
> + break;
> + case TIME_MONOTONIC:
> + clockid = CLOCK_MONOTONIC;
> + break;
> + case TIME_PROCESS_CPUTIME_ID:
> + clockid = CLOCK_PROCESS_CPUTIME_ID;
> + break;
> + case TIME_THREAD_CPUTIME_ID:
> + clockid = CLOCK_THREAD_CPUTIME_ID;
> + break;
> + case TIME_MONOTONIC_RAW:
> + clockid = CLOCK_MONOTONIC_RAW;
> + break;
> + case TIME_REALTIME_COARSE:
> + clockid = CLOCK_REALTIME_COARSE;
> + break;
> + case TIME_MONOTONIC_COARSE:
> + clockid = CLOCK_MONOTONIC_COARSE;
> + break;
> + case TIME_BOOTTIME:
> + clockid = CLOCK_BOOTTIME;
> + break;
> + case TIME_REALTIME_ALARM:
> + clockid = CLOCK_REALTIME_ALARM;
> + break;
> + case TIME_BOOTTIME_ALARM:
> + clockid = CLOCK_BOOTTIME_ALARM;
> + break;
> + case TIME_SGI_CYCLE:
> + clockid = CLOCK_SGI_CYCLE;
> + break;
> + case TIME_TAI:
> + clockid = CLOCK_TAI;
> + break;
> + }
> + if (clockid >= 0)
> {
> - __clock_gettime (CLOCK_REALTIME, ts);
> - return base;
> + if (__clock_gettime (clockid, ts) >= 0) {
> + return base;
> + }
> }
> return 0;
> }
This was recently discussed on the libc-coord list:
Relation between C timespec_get time bases and POSIX clockid_t values.
<https://www.openwall.com/lists/libc-coord/2023/04/25/1>
I'm not sure if we should extend this because it's just a bizarre WG14
not-invent-here interface, designed to be incompatible with existing
implementation practice.
Thanks,
Florian
More information about the Libc-alpha
mailing list