[2/2] libc/include/time.h: Add TIME_MONOTONIC for C23

Message ID 20260416220622.3404924-2-joel@rtems.org
State New
Headers
Series [1/2] libc/include/time.h: Add C23 timespec_getres() |

Commit Message

Joel Sherrill April 16, 2026, 10:06 p.m. UTC
  ---
 newlib/libc/include/time.h | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Howland, Craig D. - US via Newlib April 16, 2026, 11:24 p.m. UTC | #1
> 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

Craig
  
Corinna Vinschen April 19, 2026, 9:13 a.m. UTC | #2
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
  

Patch

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