diff options
author | Max <msuraev@sysmocom.de> | 2018-11-09 13:08:42 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2019-01-07 15:45:00 +0000 |
commit | 0187c3ae373f36bd0e81654ae6aa7b496f5990ea (patch) | |
tree | 20655fe1414bd6e500b9c8f62f7b092a1f42d45e /src | |
parent | 660729c3986236ae482ed38141ee952b0875e6c8 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/gsm/gsm_utils.c | 18 |
1 files changed, 11 insertions, 7 deletions
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 <sys/random.h> #elif HAVE_DECL_SYS_GETRANDOM #include <sys/syscall.h> #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; |