3ce1d654c94442d675b70a7242967cf9a773d8f8
[openwrt/staging/chunkeey.git] /
1 From 1f8a3f7bccfc84b195218ad0086ebd57049c3490 Mon Sep 17 00:00:00 2001
2 From: Guillem Jover <guillem@hadrons.org>
3 Date: Tue, 6 Mar 2018 01:39:45 +0100
4 Subject: Fix function declaration protection for glibc already providing them
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 On non-glibc based systems we cannot unconditionally use the
10 __GLIBC_PREREQ macro as it gets expanded before evaluation. Instead,
11 if it is undefined, define it to 0.
12
13 We should also always declare these functions on non-glibc based
14 systems. And on systems with a new enough glibc, which provides these
15 functions, we should still provide the declarations if _GNU_SOURCE
16 is *not* defined.
17
18 Reported-by: Jörg Krause <joerg.krause@embedded.rocks>
19 ---
20 include/bsd/stdlib.h | 3 ++-
21 include/bsd/string.h | 3 ++-
22 include/bsd/sys/cdefs.h | 8 ++++++++
23 3 files changed, 12 insertions(+), 2 deletions(-)
24
25 --- a/include/bsd/stdlib.h
26 +++ b/include/bsd/stdlib.h
27 @@ -71,7 +71,8 @@ int sradixsort(const unsigned char **bas
28 const unsigned char *table, unsigned endbyte);
29
30 void *reallocf(void *ptr, size_t size);
31 -#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26)
32 +#if !defined(__GLIBC__) || \
33 + (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 26) || !defined(_GNU_SOURCE)))
34 void *reallocarray(void *ptr, size_t nmemb, size_t size);
35 #endif
36
37 --- a/include/bsd/string.h
38 +++ b/include/bsd/string.h
39 @@ -46,7 +46,8 @@ size_t strlcat(char *dst, const char *sr
40 char *strnstr(const char *str, const char *find, size_t str_len);
41 void strmode(mode_t mode, char *str);
42
43 -#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25)
44 +#if !defined(__GLIBC__) || \
45 + (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE)))
46 void explicit_bzero(void *buf, size_t len);
47 #endif
48 __END_DECLS
49 --- a/include/bsd/sys/cdefs.h
50 +++ b/include/bsd/sys/cdefs.h
51 @@ -59,6 +59,14 @@
52 #endif
53
54 /*
55 + * On non-glibc based systems, we cannot unconditionally use the
56 + * __GLIBC_PREREQ macro as it gets expanded before evaluation.
57 + */
58 +#ifndef __GLIBC_PREREQ
59 +#define __GLIBC_PREREQ(maj, min) 0
60 +#endif
61 +
62 +/*
63 * Some kFreeBSD headers expect those macros to be set for sanity checks.
64 */
65 #ifndef _SYS_CDEFS_H_