On Tue, Jun 20, 2023 at 8:44 PM Florian Weimer wrote: > > * 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. > > > 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. These are implemented https://gustedt.gitlabpages.inria.fr/c23-library/#time_monotonic-time_active-time_thread_active So time_base = clock_id + 1 for linux/posix. But do we need guarantee that, because there so much posix implementation. Maybe we need a function named timebase_to_clockid/clockid_to_timebase in posix standard, for c standard just keep as is > > Thanks, > Florian > -- 此致 礼 罗勇刚 Yours sincerely, Yonggang Luo