add glibc versioning for a number of headers (#24237)

* 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 <alex@alexrp.com>

* 2.35 instead of 35

* before 2.35 instead of 2.34 and before

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
This commit is contained in:
Marc 2025-06-24 23:14:00 +07:00 committed by GitHub
parent 35329b510c
commit 75d6d4c3f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 0 deletions

View file

@ -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 */

View file

@ -16,6 +16,11 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
// 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

View file

@ -16,6 +16,12 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
// 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

View file

@ -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