[PATCH] libc: Add/Update prototypes For POSIX Issue 8 functions

Mazen Adel Elmessady mez3n1151@gmail.com
Sat Jun 21 21:34:24 GMT 2025


Added the prototype for sem_clockwait(), ppoll()
and timespec_get() with proper guards.
Updated the guard for pthread functions added in POSIX Issue 8
to use the POSIX Issue 8 guard added in 2024.
---
 newlib/libc/include/pthread.h             | 12 ++++++------
 newlib/libc/include/stdlib.h              |  7 ++++---
 newlib/libc/include/time.h                |  5 +++++
 newlib/libc/sys/rtems/include/semaphore.h |  6 ++++++
 newlib/libc/sys/rtems/include/sys/poll.h  |  9 +++++++++
 winsup/cygwin/include/cygwin/time.h       |  6 ------
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/newlib/libc/include/pthread.h b/newlib/libc/include/pthread.h
index c99ad395d..05ff31579 100644
--- a/newlib/libc/include/pthread.h
+++ b/newlib/libc/include/pthread.h
@@ -87,11 +87,11 @@ int	pthread_mutex_timedlock (pthread_mutex_t *__mutex,
 
 #endif /* _POSIX_TIMEOUTS */
 
-#if __GNU_VISIBLE
+#if (__GNU_VISIBLE || __POSIX_VISIBLE >= 202405)
 /* The Issue 8 standard adds pthread_mutex_clocklock() */
 int pthread_mutex_clocklock(pthread_mutex_t *__restrict, clockid_t,
 				   const struct timespec *__restrict);
-#endif /* __GNU_VISIBLE */
+#endif /* __GNU_VISIBLE || __POSIX_VISIBLE >= 202405 */
 
 /* Condition Variable Initialization Attributes, P1003.1c/Draft 10, p. 96 */
  
@@ -133,12 +133,12 @@ int	pthread_cond_timedwait (pthread_cond_t *__cond,
 				pthread_mutex_t *__mutex,
 				const struct timespec *__abstime);
 
-#if __GNU_VISIBLE
+#if (__GNU_VISIBLE || __POSIX_VISIBLE >= 202405)
 /* The Issue 8 standard adds pthread_cond_clockwait() */
 int pthread_cond_clockwait(pthread_cond_t *__restrict,
                    pthread_mutex_t *__restrict, clockid_t,
 				   const struct timespec *__restrict);
-#endif /* __GNU_VISIBLE */
+#endif /* __GNU_VISIBLE || __POSIX_VISIBLE >= 202405 */
  
 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
 
@@ -436,14 +436,14 @@ int	pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
 int	pthread_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
 				    const struct timespec *__abstime);
 
-#if __GNU_VISIBLE
+#if (__GNU_VISIBLE || __POSIX_VISIBLE >= 202405)
 /* The Issue 8 standard adds pthread_rwlock_clockrdlock()
 *  and pthread_rwlock_clockwrlock()*/
 int pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict, clockid_t,
 				   const struct timespec *__restrict);
 int pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict, clockid_t,
 				   const struct timespec *__restrict);
-#endif /* __GNU_VISIBLE */
+#endif /* __GNU_VISIBLE || __POSIX_VISIBLE >= 202405 */
 
 #endif /* defined(_POSIX_READER_WRITER_LOCKS) */
 
diff --git a/newlib/libc/include/stdlib.h b/newlib/libc/include/stdlib.h
index 0690a0377..b5482d6f3 100644
--- a/newlib/libc/include/stdlib.h
+++ b/newlib/libc/include/stdlib.h
@@ -328,15 +328,16 @@ extern long double strtold (const char *__restrict, char **__restrict);
 #endif /* _HAVE_LONG_DOUBLE */
 
 /*
- * If we're in a mode greater than C99, expose C11 functions.
+ * If we're in a mode greater than C99, expose C11 functions
+ * Or if POSIX Issue 8 is enabled.
  */
-#if __ISO_C_VISIBLE >= 2011
+#if (__ISO_C_VISIBLE >= 2011 || __POSIX_VISIBLE >= 202405)
 void *	aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1)
 	    __alloc_size(2) __result_use_check;
 int	at_quick_exit(void (*)(void));
 _Noreturn void
 	quick_exit(int);
-#endif /* __ISO_C_VISIBLE >= 2011 */
+#endif /* __ISO_C_VISIBLE >= 2011 || __POSIX_VISIBLE >= 202405 */
 
 _END_STD_C
 
diff --git a/newlib/libc/include/time.h b/newlib/libc/include/time.h
index ab3491341..a2df4f7fd 100644
--- a/newlib/libc/include/time.h
+++ b/newlib/libc/include/time.h
@@ -57,6 +57,11 @@ clock_t	   clock (void);
 double	   difftime (time_t _time2, time_t _time1);
 time_t	   mktime (struct tm *_timeptr);
 time_t	   time (time_t *_timer);
+#if (__ISO_C_VISIBLE >= 2011 || __POSIX_VISIBLE >= 202405)
+#define TIME_UTC 1
+
+int        timespec_get(struct timespec *ts, int base);
+#endif
 #ifndef _REENT_ONLY
 char	  *asctime (const struct tm *_tblock);
 char	  *ctime (const time_t *_time);
diff --git a/newlib/libc/sys/rtems/include/semaphore.h b/newlib/libc/sys/rtems/include/semaphore.h
index 939135fb3..7b43de845 100644
--- a/newlib/libc/sys/rtems/include/semaphore.h
+++ b/newlib/libc/sys/rtems/include/semaphore.h
@@ -55,6 +55,12 @@ int	 sem_timedwait(sem_t * __restrict, const struct timespec * __restrict);
 int	 sem_trywait(sem_t *);
 int	 sem_unlink(const char *);
 int	 sem_wait(sem_t *);
+
+#if __POSIX_VISIBLE >= 202405
+int sem_clockwait(sem_t * __restrict, __clockid_t,
+       const struct timespec * __restrict);
+#endif /* __POSIX_VISIBLE >= 202405 */
+
 __END_DECLS
 
 #endif /* !_SEMAPHORE_H_ */
diff --git a/newlib/libc/sys/rtems/include/sys/poll.h b/newlib/libc/sys/rtems/include/sys/poll.h
index cc6ad49db..827f4ae2e 100644
--- a/newlib/libc/sys/rtems/include/sys/poll.h
+++ b/newlib/libc/sys/rtems/include/sys/poll.h
@@ -35,6 +35,10 @@
 
 #include <sys/cdefs.h>
 
+#if __POSIX_VISIBLE >= 202405
+#include <signal.h>
+#endif
+
 /*
  * This file is intended to be compatible with the traditional poll.h.
  */
@@ -100,6 +104,11 @@ struct pollfd {
 
 __BEGIN_DECLS
 int	poll(struct pollfd _pfd[], nfds_t _nfds, int _timeout);
+#if __POSIX_VISIBLE >= 202405
+int	ppoll(struct pollfd _pfd[], nfds_t _nfds,
+	    const struct timespec *__restrict _timeout,
+	    const sigset_t *__restrict _newsigmask);
+#endif
 __END_DECLS
 
 #endif /* !_KERNEL */
diff --git a/winsup/cygwin/include/cygwin/time.h b/winsup/cygwin/include/cygwin/time.h
index 9b63e9aeb..d7f9d3f75 100644
--- a/winsup/cygwin/include/cygwin/time.h
+++ b/winsup/cygwin/include/cygwin/time.h
@@ -35,12 +35,6 @@ extern long timezone __asm__ (_SYMSTR (_timezone));
 
 #endif /* __SVID_VISIBLE || __XSI_VISIBLE */
 
-#if __ISO_C_VISIBLE >= 2011
-#define TIME_UTC 1
-
-extern int timespec_get (struct timespec *, int);
-#endif
-
 #ifdef __cplusplus
 }
 #endif
-- 
2.48.1



More information about the Newlib mailing list