[PATCH] Fix build if __GLIBC_PREREQ is not defined

Jörg Krause joerg.krause at embedded.rocks
Fri Mar 2 07:03:40 UTC 2018


__GLIBC_PREREQ is specific to glibc so it should be checked if it is
defined or not.

Fixes build error with musl:
'''
../include/bsd/stdlib.h:70:66: error: missing binary operator before token "("
 #if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26)
'''

Signed-off-by: Jörg Krause <joerg.krause at embedded.rocks>
---
 include/bsd/stdlib.h | 4 +++-
 include/bsd/string.h | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index ebc9638..6cd7943 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -67,9 +67,11 @@ 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(_GNU_SOURCE) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if !__GLIBC_PREREQ(2, 26)
 void *reallocarray(void *ptr, size_t nmemb, size_t size);
 #endif
+#endif
 
 long long strtonum(const char *nptr, long long minval, long long maxval,
                    const char **errstr);
diff --git a/include/bsd/string.h b/include/bsd/string.h
index 6798bf6..50542ee 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -42,9 +42,11 @@ 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(_GNU_SOURCE) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if !__GLIBC_PREREQ(2, 25)
 void explicit_bzero(void *buf, size_t len);
 #endif
+#endif
 __END_DECLS
 
 #endif
-- 
2.16.2



More information about the libbsd mailing list