From 75d6d4c3f20423eede8ecaf7bcc4eaa501c1af9d Mon Sep 17 00:00:00 2001 From: Marc Date: Tue, 24 Jun 2025 23:14:00 +0700 Subject: [PATCH] add glibc versioning for a number of headers (#24237) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * getrandom was added in glibc 2.25 https://sourceware.org/bugzilla/show_bug.cgi?id=17252 * copy_file_range was added in glibc 2.27 https://sourceware.org/git/?p=glibc.git;a=commit;h=bad7a0c81f501fbbcc79af9eaa4b8254441c4a1f * threads.h should not exist for glibc < 2.28 * single_threaded.h should not exist for glibc < 2.35 * Apply suggestions from code review Co-authored-by: Alex Rønne Petersen * 2.35 instead of 35 * before 2.35 instead of 2.34 and before --------- Co-authored-by: Alex Rønne Petersen --- lib/libc/include/generic-glibc/sys/random.h | 5 +++++ lib/libc/include/generic-glibc/sys/single_threaded.h | 5 +++++ lib/libc/include/generic-glibc/threads.h | 6 ++++++ lib/libc/include/generic-glibc/unistd.h | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/lib/libc/include/generic-glibc/sys/random.h b/lib/libc/include/generic-glibc/sys/random.h index df47dfa6e6..b1df7f4338 100644 --- a/lib/libc/include/generic-glibc/sys/random.h +++ b/lib/libc/include/generic-glibc/sys/random.h @@ -29,6 +29,9 @@ __BEGIN_DECLS +// zig patch: getrandom and getentropy were added in glibc 2.25 +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25) || __GLIBC__ > 2 + /* Write LENGTH bytes of randomness starting at BUFFER. Return the number of bytes written, or -1 on error. */ ssize_t getrandom (void *__buffer, size_t __length, @@ -40,6 +43,8 @@ ssize_t getrandom (void *__buffer, size_t __length, int getentropy (void *__buffer, size_t __length) __wur __attr_access ((__write_only__, 1, 2)); +#endif /* glibc 2.25 or later */ + __END_DECLS #endif /* _SYS_RANDOM_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-glibc/sys/single_threaded.h b/lib/libc/include/generic-glibc/sys/single_threaded.h index eaaca5984a..b5a93d084a 100644 --- a/lib/libc/include/generic-glibc/sys/single_threaded.h +++ b/lib/libc/include/generic-glibc/sys/single_threaded.h @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +// zig patch: sys/single_threaded.h header was added in glibc 2.35 +#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 35 + #error "sys/single_threaded.h did not exist before glibc 2.35" +#endif /* error for glibc before 2.35 */ + #ifndef _SYS_SINGLE_THREADED_H #define _SYS_SINGLE_THREADED_H diff --git a/lib/libc/include/generic-glibc/threads.h b/lib/libc/include/generic-glibc/threads.h index 3bec8915f3..44febdd5e6 100644 --- a/lib/libc/include/generic-glibc/threads.h +++ b/lib/libc/include/generic-glibc/threads.h @@ -16,6 +16,12 @@ License along with the GNU C Library; if not, see . */ + +// zig patch: threads header was added in glibc 2.28 +#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 28 + #error "threads.h did not exist before glibc 2.28" +#endif /* error for glibc before 2.28 */ + #ifndef _THREADS_H #define _THREADS_H 1 diff --git a/lib/libc/include/generic-glibc/unistd.h b/lib/libc/include/generic-glibc/unistd.h index 3174cb0994..7bc48ec48b 100644 --- a/lib/libc/include/generic-glibc/unistd.h +++ b/lib/libc/include/generic-glibc/unistd.h @@ -1138,10 +1138,16 @@ extern int lockf64 (int __fd, int __cmd, __off64_t __len) __wur; while (__result == -1L && errno == EINTR); \ __result; })) +// zig patch: copy_file_range was added in glibc 2.27 +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 27) || __GLIBC__ > 2 + /* Copy LENGTH bytes from INFD to OUTFD. */ ssize_t copy_file_range (int __infd, __off64_t *__pinoff, int __outfd, __off64_t *__poutoff, size_t __length, unsigned int __flags); + +#endif /* glibc 2.27 or later */ + #endif /* __USE_GNU */ #if defined __USE_POSIX199309 || defined __USE_UNIX98