From: Emil Velikov Date: Sat, 24 May 2025 15:21:18 +0000 (+0100) Subject: Convert most #ifdef HAVE_FOO checks to #if HAVE_FOO X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1996121ec105198928f37cdd16f87e2ac0a206e3;p=thirdparty%2Fkmod.git Convert most #ifdef HAVE_FOO checks to #if HAVE_FOO The former is somewhat error prone, since the pre-processor will evaluate the presence of the define, which might have been omitted due to wrong include or otherwise. Swap for the other solution we already have in-tree - always set the relevant define(s) and evaluate them numerically. That combined with -Wundef means that we'll get meaningful compiler warning when we get something wrong. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/356 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h index d78a2756..547b8369 100644 --- a/libkmod/libkmod-internal.h +++ b/libkmod/libkmod-internal.h @@ -27,7 +27,7 @@ #define KCMD_LINE_SIZE 4096 -#ifndef HAVE_SECURE_GETENV +#if !HAVE_SECURE_GETENV #warning secure_getenv is not available #define secure_getenv getenv #endif diff --git a/meson.build b/meson.build index 4f3e9551..4a718275 100644 --- a/meson.build +++ b/meson.build @@ -27,8 +27,6 @@ cc = meson.get_compiler('c') # We rely on the glibc variant of basename, et al. cdata.set10('_GNU_SOURCE', true) -# TODO: Once meson-only, adjust all #ifdef X to if X and convert .set to .set10 - ################################################################################ # Function and structure checks ################################################################################ @@ -38,9 +36,7 @@ _funcs = [ 'secure_getenv', ] foreach func : _funcs - if cc.has_function(func, args : '-D_GNU_SOURCE') - cdata.set('HAVE_@0@'.format(func.to_upper()), true) - endif + cdata.set10('HAVE_@0@'.format(func.to_upper()), cc.has_function(func, args : '-D_GNU_SOURCE')) endforeach # Meson has some amount of support for finding builtins by passing the symbol @@ -94,17 +90,8 @@ foreach tuple : _decls cdata.set10('HAVE_DECL_@0@'.format(decl.to_upper()), have) endforeach -if cc.compiles('_Static_assert(1, "Test");', name : '_Static_assert') - cdata.set('HAVE_STATIC_ASSERT', true) -endif - -if cc.compiles(''' - #include - _Noreturn int foo(void) { exit(0); } - ''', - name : '_Noreturn') - cdata.set('HAVE_NORETURN', true) -endif +cdata.set10('HAVE_STATIC_ASSERT', cc.compiles('_Static_assert(1, "Test");', name : '_Static_assert')) +cdata.set10('HAVE_NORETURN', cc.compiles('#include ; _Noreturn int foo(void) { exit(0); }', name : '_Noreturn')) ################################################################################ # Default CFLAGS and LDFLAGS diff --git a/shared/macro.h b/shared/macro.h index 8829d0b6..15a95a3b 100644 --- a/shared/macro.h +++ b/shared/macro.h @@ -6,7 +6,7 @@ #include -#if defined(HAVE_STATIC_ASSERT) +#if HAVE_STATIC_ASSERT #define assert_cc(expr) _Static_assert((expr), #expr) #else #define assert_cc(expr) \ @@ -73,7 +73,7 @@ static inline void freep(void *p) /* Define C11 noreturn without and even on older gcc * compiler versions */ #ifndef noreturn -#if defined(HAVE_NORETURN) +#if HAVE_NORETURN #define noreturn _Noreturn #else #define noreturn __attribute__((noreturn)) diff --git a/testsuite/path.c b/testsuite/path.c index 25548f49..3024d50e 100644 --- a/testsuite/path.c +++ b/testsuite/path.c @@ -175,19 +175,19 @@ WRAP_2ARGS(int, -1, stat, struct stat *); WRAP_OPEN(); -#ifdef HAVE_FOPEN64 +#if HAVE_FOPEN64 WRAP_2ARGS(FILE *, NULL, fopen64, const char *); #endif -#ifdef HAVE_STAT64 +#if HAVE_STAT64 WRAP_2ARGS(int, -1, stat64, struct stat64 *); #endif -#ifdef HAVE___STAT64_TIME64 +#if HAVE___STAT64_TIME64 extern int __stat64_time64(const char *file, void *buf); WRAP_2ARGS(int, -1, __stat64_time64, void *); #endif -#ifdef HAVE_OPEN64 +#if HAVE_OPEN64 WRAP_OPEN(64); #endif