[PATCH 2/2] libc/include/time.h: Add TIME_MONOTONIC for C23
Corinna Vinschen
corinna@vinschen.de
Sun Apr 19 09:13:38 GMT 2026
On Apr 16 23:24, Howland, Craig D. - US via Newlib wrote:
> > From: Joel Sherrill <joel@rtems.org>
> > Sent: Thursday, April 16, 2026 6:06 PM
> > To: newlib@sourceware.org <newlib@sourceware.org>
> > Cc: Joel Sherrill <joel@rtems.org>
> > Subject: [PATCH 2/2] libc/include/time.h: Add TIME_MONOTONIC for C23
> > ---
> > newlib/libc/include/time.h | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/newlib/libc/include/time.h b/newlib/libc/include/time.h
> > index e972bd416..429dd8bd9 100644
> > --- a/newlib/libc/include/time.h
> > +++ b/newlib/libc/include/time.h
> > @@ -63,6 +63,9 @@ time_t time (time_t *_timer);
> > int timespec_get(struct timespec *ts, int base);
> > #endif
> > #if (__ISO_C_VISIBLE >= 2023)
> > +#define TIME_MONOTONIC 2
> > +#endif
> > +#if (__ISO_C_VISIBLE >= 2023)
> > int timespec_getres(struct timespec *ts, int base);
> > #endif
> > #ifndef _REENT_ONLY
>
> Any particular reason for two of the same #if? I can't think of one, merge them.
> Additionally, this also could be grouped within the preceding #if (__ISO_C_VISIBLE >= 2011 || __POSIX_VISIBLE >= 202405), which would make it read a little more cleanly.
> Speaking of cleanly, this diff appears to be based on a corrupted file version, fails to apply. (It is lacking #define TIME_UTC, e.g.)
>
> Snippet from present time.h:
>
> #if (__ISO_C_VISIBLE >= 2011 || __POSIX_VISIBLE >= 202405)
> #define TIME_UTC 1
>
> int timespec_get(struct timespec *ts, int base);
> #endif
>
> Suggested end result:
> #if (__ISO_C_VISIBLE >= 2011 || __POSIX_VISIBLE >= 202405)
> #define TIME_UTC 1
> int timespec_get(struct timespec *ts, int base);
> #if (__ISO_C_VISIBLE >= 2023)
> #define TIME_MONOTONIC 2
> int timespec_getres(struct timespec *ts, int base);
> #endif
> #endif
Actually, the definitions TIME_UTC and TIME_MONOTONIC should
be adjacent to each other. And if TIME_MONOTONIC gets defined,
TIME_ACTIVE and TIME_THREAD_ACTIVE should be defined as well,
me thinks:
#if (__ISO_C_VISIBLE >= 2011 || __POSIX_VISIBLE >= 202405)
#define TIME_UTC 1
#endif
#if (__ISO_C_VISIBLE >= 2023)
#define TIME_MONOTONIC 2
#define TIME_ACTIVE 3
#define TIME_THREAD_ACTIVE 4
#endif
and only after that the related functions should be defined. It might
be a good idea, to separate out the above macros as well as the
functions timespec_get and timespec_getres into it's own block in
time.h, too.
Corinna
More information about the Newlib
mailing list