[PATCH] Fix build if __GLIBC_PREREQ is not defined
Jörg Krause
joerg.krause at embedded.rocks
Wed Mar 7 20:13:40 UTC 2018
Hi all,
On Fri, 2018-03-02 at 08:03 +0100, Jörg Krause wrote:
> __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
I've noticed that this patch allows building with musl, but produces
warnings because of implicit function declarations.
An improved version of the patch could be for example:
'''
#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 25)
#define HAVE_EXPLICIT_BZERO
#endif
#endif
__BEGIN_DECLS
[...]
#if defined(_GNU_SOURCE) && !defined(HAVE_EXPLICIT_BZERO)
void explicit_bzero(void *buf, size_t len);
#endif
__END_DECLS
'''
Would do you think?
Best regards,
Jörg Krause
More information about the libbsd
mailing list