From 0187c3ae373f36bd0e81654ae6aa7b496f5990ea Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 9 Nov 2018 13:08:42 +0100 Subject: Streamline glibc version check * use macro for version check * report glibc version upon random.h detection * comment where various #endif belongs to * explicitly check for embedded build (our target toolchain don't use libc so there's no point in checking its version) Change-Id: Ia54f0b7a861f955be65bb0cf06eb10af9372d062 --- src/gsm/gsm_utils.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c index 9eb41fb5..14331e59 100644 --- a/src/gsm/gsm_utils.c +++ b/src/gsm/gsm_utils.c @@ -98,15 +98,18 @@ #include "../../config.h" +#if (!EMBEDDED) /* FIXME: this can be removed once we bump glibc requirements to 2.25: */ -#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25) +#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2,25) +#pragma message ("glibc " OSMO_STRINGIFY_VAL(__GLIBC__) "." OSMO_STRINGIFY_VAL(__GLIBC_MINOR__) " random detected") #include #elif HAVE_DECL_SYS_GETRANDOM #include #ifndef GRND_NONBLOCK #define GRND_NONBLOCK 0x0001 -#endif -#endif +#endif /* ifndef GRND_NONBLOCK */ +#endif /* if __GLIBC_PREREQ */ +#endif /* !EMBEDDED */ #if (USE_GNUTLS) #pragma message ("including GnuTLS for getrandom fallback.") @@ -131,7 +134,8 @@ static void on_dso_unload_gnutls(void) if (!gnutls_check_version("3.3.0")) gnutls_global_deinit(); } -#endif + +#endif /* if (USE_GNUTLS) */ /* ETSI GSM 03.38 6.2.1 and 6.2.1.1 default alphabet * Greek symbols at hex positions 0x10 and 0x12-0x1a @@ -441,19 +445,19 @@ int osmo_get_rand_id(uint8_t *out, size_t len) /* this function is intended for generating short identifiers only, not arbitrary-length random data */ if (len > OSMO_MAX_RAND_ID_LEN) return -E2BIG; - -#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25) +#if (!EMBEDDED) +#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2,25) rc = getrandom(out, len, GRND_NONBLOCK); #elif HAVE_DECL_SYS_GETRANDOM #pragma message ("Using direct syscall access for getrandom(): consider upgrading to glibc >= 2.25") /* FIXME: this can be removed once we bump glibc requirements to 2.25: */ rc = syscall(SYS_getrandom, out, len, GRND_NONBLOCK); #endif +#endif /* !EMBEDDED */ /* getrandom() failed entirely: */ if (rc < 0) { #if (USE_GNUTLS) -#pragma message ("Secure random failed: using GnuTLS fallback.") return gnutls_rnd(GNUTLS_RND_RANDOM, out, len); #endif return -errno; -- cgit v1.2.3