]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Fix function declaration protection for glibc already providing them
authorGuillem Jover <guillem@hadrons.org>
Tue, 6 Mar 2018 00:39:45 +0000 (01:39 +0100)
committerGuillem Jover <guillem@hadrons.org>
Tue, 13 Mar 2018 01:28:53 +0000 (02:28 +0100)
On non-glibc based systems we cannot unconditionally use the
__GLIBC_PREREQ macro as it gets expanded before evaluation. Instead,
if it is undefined, define it to 0.

We should also always declare these functions on non-glibc based
systems. And on systems with a new enough glibc, which provides these
functions, we should still provide the declarations if _GNU_SOURCE
is *not* defined.

Reported-by: Jörg Krause <joerg.krause@embedded.rocks>
include/bsd/stdlib.h
include/bsd/string.h
include/bsd/sys/cdefs.h

index 8d33d1fc9de39565e9e20a34133f25855adb5ad5..a5b063c71c61e10f6df4be0b654571145d097b5b 100644 (file)
@@ -71,7 +71,8 @@ int sradixsort(const unsigned char **base, int nmemb,
                const unsigned char *table, unsigned endbyte);
 
 void *reallocf(void *ptr, size_t size);
-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26)
+#if !defined(__GLIBC__) || \
+    (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 26) || !defined(_GNU_SOURCE)))
 void *reallocarray(void *ptr, size_t nmemb, size_t size);
 #endif
 
index 29097f66b6c107ffc824a17249f26aab278caab4..f987fee3ed3c6c2ad0e5ec9aba1fcb2897a45f9f 100644 (file)
@@ -46,7 +46,8 @@ size_t strlcat(char *dst, const char *src, size_t siz);
 char *strnstr(const char *str, const char *find, size_t str_len);
 void strmode(mode_t mode, char *str);
 
-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25)
+#if !defined(__GLIBC__) || \
+    (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE)))
 void explicit_bzero(void *buf, size_t len);
 #endif
 __END_DECLS
index b4c8f303ea15303fc17f437b436563a1ae896559..d1cc41920a4c968e792c63588a32393cee7fa614 100644 (file)
 #endif
 #endif
 
+/*
+ * On non-glibc based systems, we cannot unconditionally use the
+ * __GLIBC_PREREQ macro as it gets expanded before evaluation.
+ */
+#ifndef __GLIBC_PREREQ
+#define __GLIBC_PREREQ(maj, min) 0
+#endif
+
 /*
  * Some kFreeBSD headers expect those macros to be set for sanity checks.
  */