[v2] unistd: use __USE_XOPEN2K24 for existing POSIX.1-2024 interfaces

Message ID 632f80de101ddfc0af2bcb7a23fb82cad2ec70a3.1771988307.git.collin.funk1@gmail.com (mailing list archive)
State New
Headers
Series [v2] unistd: use __USE_XOPEN2K24 for existing POSIX.1-2024 interfaces |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
redhat-pt-bot/TryBot-still_applies warning Patch no longer applies to master

Commit Message

Collin Funk Feb. 25, 2026, 2:58 a.m. UTC
  * posix/unistd.h (SEEK_DATA, SEEK_HOLE, pipe2, dup2, getresgid)
(getresuid, setresgid, setresuid, _Fork): Make visible when
__USE_XOPEN2K24 is defined, which is also defined when __USE_GNU is
defined.
(getentropy): Also define when __USE_XOPEN2K24 is defined.
* conform/data/unistd.h-data: Add checks for the prototypes, although
conform has not yet been adjusted to support POSIX.1-2024.
---
 conform/data/unistd.h-data | 25 +++++++++++++++++++++++++
 posix/unistd.h             | 12 ++++++------
 2 files changed, 31 insertions(+), 6 deletions(-)
  

Comments

Joseph Myers Feb. 25, 2026, 4:33 p.m. UTC | #1
On Tue, 24 Feb 2026, Collin Funk wrote:

> * conform/data/unistd.h-data: Add checks for the prototypes, although
> conform has not yet been adjusted to support POSIX.1-2024.

I'm not convinced it's coherent to put POSIX24 conditionals in the 
conform/ data without first doing the mechanical preparation that makes it 
a duplicate of POSIX2008 (better: makes POSIX2024 a duplicate of POSIX2008 
and XOPEN2024 a duplicate of XOPEN2K8).  Without such mechanical 
preparation, it's essentially random what the expectations for any new 
standard would look like.
  
Collin Funk Feb. 26, 2026, 4:06 a.m. UTC | #2
Joseph Myers <josmyers@redhat.com> writes:

> On Tue, 24 Feb 2026, Collin Funk wrote:
>
>> * conform/data/unistd.h-data: Add checks for the prototypes, although
>> conform has not yet been adjusted to support POSIX.1-2024.
>
> I'm not convinced it's coherent to put POSIX24 conditionals in the 
> conform/ data without first doing the mechanical preparation that makes it 
> a duplicate of POSIX2008 (better: makes POSIX2024 a duplicate of POSIX2008 
> and XOPEN2024 a duplicate of XOPEN2K8).  Without such mechanical 
> preparation, it's essentially random what the expectations for any new 
> standard would look like.

Oh, I realize now that POSIX.1-2024 is based on C17 since it was started
long before C23. That means we don't have to worry about whether the
compiler supports -std=c2x or -std=c23.

I sent patches doing as you said in your message [1], and it shouldn't
be too much effort after to get them passing. We can then change the
headers while updating the conform tests. So lets hold off on this patch
until those are complete.

Collin

[1] https://inbox.sourceware.org/libc-alpha/cover.1772078427.git.collin.funk1@gmail.com/T/#m88e6dbc3945457d212468db6df59f0e9cc2f947e
  

Patch

diff --git a/conform/data/unistd.h-data b/conform/data/unistd.h-data
index b4531868fd..2846d1cf5c 100644
--- a/conform/data/unistd.h-data
+++ b/conform/data/unistd.h-data
@@ -171,6 +171,11 @@  constant SEEK_SET
 constant SEEK_CUR
 constant SEEK_END
 
+#ifdef POSIX24
+constant SEEK_DATA
+constant SEEK_HOLE
+#endif
+
 #ifndef POSIX
 constant _SC_2_C_BIND
 #endif
@@ -446,6 +451,9 @@  allow cuserid
 #endif
 function int dup (int)
 function int dup2 (int, int)
+#ifdef POSIX24
+function int dup3 (int, int, int)
+#endif
 function int execl (const char*, const char*, ...)
 function int execle (const char*, const char*, ...)
 function int execlp (const char*, const char*, ...)
@@ -468,6 +476,9 @@  function int fchdir (int)
 #if !defined XPG4 && !defined XPG42
 function int fdatasync (int)
 #endif
+#ifdef POSIX24
+function pid_t _Fork (void)
+#endif
 # if defined XOPEN2K8 || defined POSIX2008
 function int fexecve (int, char *const[], char *const[])
 # endif
@@ -483,6 +494,9 @@  function int getdtablesize (void)
 #endif
 function gid_t getegid (void)
 function uid_t geteuid (void)
+#ifdef POSIX24
+function int getentropy (void*, size_t)
+#endif
 function gid_t getgid (void)
 function int getgroups (int, gid_t[])
 #if !defined XPG4 && !defined POSIX && !defined POSIX2008
@@ -508,6 +522,10 @@  function pid_t getpgid (pid_t)
 function pid_t getpgrp (void)
 function pid_t getpid (void)
 function pid_t getppid (void)
+#ifdef POSIX24
+function int getresgid (gid_t*, gid_t*, gid_t*)
+function int getresuid (uid_t*, uid_t*, uid_t*)
+#endif
 #if !defined XPG4 && !defined POSIX
 function pid_t getsid (pid_t)
 #endif
@@ -533,6 +551,9 @@  function int nice (int)
 function {long int} pathconf (const char*, int)
 function int pause (void)
 function int pipe (int[2])
+#ifdef POSIX24
+function int pipe2 (int[2], int)
+#endif
 #if !defined POSIX && !defined XPG4 && !defined XPG42
 function ssize_t pread (int, void*, size_t, off_t)
 #endif
@@ -564,6 +585,10 @@  function pid_t setpgrp (void)
 function int setregid (gid_t, gid_t)
 function int setreuid (uid_t, uid_t)
 # endif
+#ifdef POSIX24
+function int setresgid (gid_t, gid_t, gid_t)
+function int setresuid (uid_t, uid_t, uid_t)
+#endif
 function pid_t setsid (void)
 function int setuid (uid_t)
 function {unsigned int} sleep (unsigned int)
diff --git a/posix/unistd.h b/posix/unistd.h
index 06a6a88b52..6bfc5a2d29 100644
--- a/posix/unistd.h
+++ b/posix/unistd.h
@@ -316,7 +316,7 @@  extern int faccessat (int __fd, const char *__file, int __type, int __flag)
 # define SEEK_SET	0	/* Seek from beginning of file.  */
 # define SEEK_CUR	1	/* Seek from current position.  */
 # define SEEK_END	2	/* Seek from end of file.  */
-# ifdef __USE_GNU
+# ifdef __USE_XOPEN2K24
 #  define SEEK_DATA	3	/* Seek to next data.  */
 #  define SEEK_HOLE	4	/* Seek to next hole.  */
 # endif
@@ -436,7 +436,7 @@  extern ssize_t pwrite64 (int __fd, const void *__buf, size_t __n,
    Returns 0 if successful, -1 if not.  */
 extern int pipe (int __pipedes[2]) __THROW __wur;
 
-#ifdef __USE_GNU
+#ifdef __USE_XOPEN2K24
 /* Same as pipe but apply flags passed in FLAGS to the new file
    descriptors.  */
 extern int pipe2 (int __pipedes[2], int __flags) __THROW __wur;
@@ -554,7 +554,7 @@  extern int dup (int __fd) __THROW __wur;
 /* Duplicate FD to FD2, closing FD2 and making it open on the same file.  */
 extern int dup2 (int __fd, int __fd2) __THROW;
 
-#ifdef __USE_GNU
+#ifdef __USE_XOPEN2K24
 /* Duplicate FD to FD2, closing FD2 and making it open on the same
    file while setting flags according to FLAGS.  */
 extern int dup3 (int __fd, int __fd2, int __flags) __THROW;
@@ -749,7 +749,7 @@  extern int setregid (__gid_t __rgid, __gid_t __egid) __THROW __wur;
 extern int setegid (__gid_t __gid) __THROW __wur;
 #endif /* Use POSIX.1-2001.  */
 
-#ifdef __USE_GNU
+#ifdef __USE_XOPEN2K24
 /* Fetch the real user ID, effective user ID, and saved-set user ID,
    of the calling process.  */
 extern int getresuid (__uid_t *__ruid, __uid_t *__euid, __uid_t *__suid)
@@ -786,7 +786,7 @@  extern __pid_t fork (void) __THROWNL;
 extern __pid_t vfork (void) __THROW;
 #endif /* Use misc or XPG < 7. */
 
-#ifdef __USE_GNU
+#ifdef __USE_XOPEN2K24
 /* This is similar to fork, however it does not run the atfork handlers
    neither reinitialize any internal locks in multithread case.
    Different than fork, _Fork is async-signal-safe.  */
@@ -1195,7 +1195,7 @@  extern int pthread_atfork (void (*__prepare) (void),
 			   void (*__child) (void)) __THROW;
 #endif
 
-#ifdef __USE_MISC
+#if defined __USE_MISC || defined __USE_XOPEN2K24
 /* Write LENGTH bytes of randomness starting at BUFFER.  Return 0 on
    success or -1 on error.  */
 int getentropy (void *__buffer, size_t __length) __wur