authorgravatar for m@pyc.acMarc <m@pyc.ac> 2025-06-24 23:14:00+07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-06-24 16:14:00+00:00
log75d6d4c3f20423eede8ecaf7bcc4eaa501c1af9d
tree3123352e95386733edebf61e495d4c198f3d789e
parent35329b510c26efdc95fdb79a041d8e0b04381126
signaturebadge-check Signed by PGP key B5690EEEBB952194

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>

4 files changed, 22 insertions(+), 0 deletions(-)

lib/libc/include/generic-glibc/sys/random.h+5
...@@ -29,6 +29,9 @@...@@ -29,6 +29,9 @@
2929
30__BEGIN_DECLS30__BEGIN_DECLS
3131
32// zig patch: getrandom and getentropy were added in glibc 2.25
33#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25) || __GLIBC__ > 2
34
32/* Write LENGTH bytes of randomness starting at BUFFER. Return the35/* Write LENGTH bytes of randomness starting at BUFFER. Return the
33 number of bytes written, or -1 on error. */36 number of bytes written, or -1 on error. */
34ssize_t getrandom (void *__buffer, size_t __length,37ssize_t getrandom (void *__buffer, size_t __length,
...@@ -40,6 +43,8 @@ ssize_t getrandom (void *__buffer, size_t __length,...@@ -40,6 +43,8 @@ ssize_t getrandom (void *__buffer, size_t __length,
40int getentropy (void *__buffer, size_t __length) __wur43int getentropy (void *__buffer, size_t __length) __wur
41 __attr_access ((__write_only__, 1, 2));44 __attr_access ((__write_only__, 1, 2));
4245
46#endif /* glibc 2.25 or later */
47
43__END_DECLS48__END_DECLS
4449
45#endif /* _SYS_RANDOM_H */50#endif /* _SYS_RANDOM_H */
\ No newline at end of file
lib/libc/include/generic-glibc/sys/single_threaded.h+5
...@@ -16,6 +16,11 @@...@@ -16,6 +16,11 @@
16 License along with the GNU C Library; if not, see16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */17 <https://www.gnu.org/licenses/>. */
1818
19// zig patch: sys/single_threaded.h header was added in glibc 2.35
20#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 35
21 #error "sys/single_threaded.h did not exist before glibc 2.35"
22#endif /* error for glibc before 2.35 */
23
19#ifndef _SYS_SINGLE_THREADED_H24#ifndef _SYS_SINGLE_THREADED_H
20#define _SYS_SINGLE_THREADED_H25#define _SYS_SINGLE_THREADED_H
2126
lib/libc/include/generic-glibc/threads.h+6
...@@ -16,6 +16,12 @@...@@ -16,6 +16,12 @@
16 License along with the GNU C Library; if not, see16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */17 <https://www.gnu.org/licenses/>. */
1818
19
20// zig patch: threads header was added in glibc 2.28
21#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 28
22 #error "threads.h did not exist before glibc 2.28"
23#endif /* error for glibc before 2.28 */
24
19#ifndef _THREADS_H25#ifndef _THREADS_H
20#define _THREADS_H 126#define _THREADS_H 1
2127
lib/libc/include/generic-glibc/unistd.h+6
...@@ -1138,10 +1138,16 @@ extern int lockf64 (int __fd, int __cmd, __off64_t __len) __wur;...@@ -1138,10 +1138,16 @@ extern int lockf64 (int __fd, int __cmd, __off64_t __len) __wur;
1138 while (__result == -1L && errno == EINTR); \1138 while (__result == -1L && errno == EINTR); \
1139 __result; }))1139 __result; }))
11401140
1141// zig patch: copy_file_range was added in glibc 2.27
1142#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 27) || __GLIBC__ > 2
1143
1141/* Copy LENGTH bytes from INFD to OUTFD. */1144/* Copy LENGTH bytes from INFD to OUTFD. */
1142ssize_t copy_file_range (int __infd, __off64_t *__pinoff,1145ssize_t copy_file_range (int __infd, __off64_t *__pinoff,
1143 int __outfd, __off64_t *__poutoff,1146 int __outfd, __off64_t *__poutoff,
1144 size_t __length, unsigned int __flags);1147 size_t __length, unsigned int __flags);
1148
1149#endif /* glibc 2.27 or later */
1150
1145#endif /* __USE_GNU */1151#endif /* __USE_GNU */
11461152
1147#if defined __USE_POSIX199309 || defined __USE_UNIX981153#if defined __USE_POSIX199309 || defined __USE_UNIX98