Skip to content

Commit 75d6d4c

Browse files
henderkesalexrp
andauthored
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>
1 parent 35329b5 commit 75d6d4c

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

lib/libc/include/generic-glibc/sys/random.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
__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+
3235
/* Write LENGTH bytes of randomness starting at BUFFER. Return the
3336
number of bytes written, or -1 on error. */
3437
ssize_t getrandom (void *__buffer, size_t __length,
@@ -40,6 +43,8 @@ ssize_t getrandom (void *__buffer, size_t __length,
4043
int getentropy (void *__buffer, size_t __length) __wur
4144
__attr_access ((__write_only__, 1, 2));
4245

46+
#endif /* glibc 2.25 or later */
47+
4348
__END_DECLS
4449

4550
#endif /* _SYS_RANDOM_H */

lib/libc/include/generic-glibc/sys/single_threaded.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
License along with the GNU C Library; if not, see
1717
<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+
1924
#ifndef _SYS_SINGLE_THREADED_H
2025
#define _SYS_SINGLE_THREADED_H
2126

lib/libc/include/generic-glibc/threads.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
License along with the GNU C Library; if not, see
1717
<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+
1925
#ifndef _THREADS_H
2026
#define _THREADS_H 1
2127

lib/libc/include/generic-glibc/unistd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,10 +1138,16 @@ extern int lockf64 (int __fd, int __cmd, __off64_t __len) __wur;
11381138
while (__result == -1L && errno == EINTR); \
11391139
__result; }))
11401140

1141+
// zig patch: copy_file_range was added in glibc 2.27
1142+
#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 27) || __GLIBC__ > 2
1143+
11411144
/* Copy LENGTH bytes from INFD to OUTFD. */
11421145
ssize_t copy_file_range (int __infd, __off64_t *__pinoff,
11431146
int __outfd, __off64_t *__poutoff,
11441147
size_t __length, unsigned int __flags);
1148+
1149+
#endif /* glibc 2.27 or later */
1150+
11451151
#endif /* __USE_GNU */
11461152

11471153
#if defined __USE_POSIX199309 || defined __USE_UNIX98

0 commit comments

Comments
 (0)