From: Denis Ovsienko Date: Thu, 28 Mar 2024 11:32:41 +0000 (+0000) Subject: When necessary, trust the OS to implement ffs(). X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/fd42316d094b9930f7f7a57ea63fbd1c7ec04ccf When necessary, trust the OS to implement ffs(). Eliminate some dead code and two more build-time checks in Autoconf and CMake. --- diff --git a/CHANGES b/CHANGES index 45d51da0..d4701dff 100644 --- a/CHANGES +++ b/CHANGES @@ -48,6 +48,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group Make FreeBSD, Linux and macOS builds warning-free. Fix propagation of cc_werr_cflags() output. Print MAC addresses in findalldevstest. + When necessary, trust the OS to implement ffs(). Hurd: Support network capture devices too. Fix a few device activation bugs. diff --git a/CMakeLists.txt b/CMakeLists.txt index af0ae3ab..1c47169d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1077,20 +1077,6 @@ else(WIN32) check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN) endif(WIN32) -# -# Do we have ffs(), and is it declared in ? -# -check_function_exists(ffs HAVE_FFS) -if(HAVE_FFS) - # - # OK, we have ffs(). Is it declared in ? - # - # This test fails if we don't have or if we do - # but it doesn't declare ffs(). - # - check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS) -endif() - # # This requires the libraries that we require, as ether_hostton might be # in one of those libraries. That means we have to do this after diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 140d14b9..a0a11335 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -289,9 +289,6 @@ /* The size of `void *', as computed by sizeof. */ #cmakedefine SIZEOF_VOID_P @SIZEOF_VOID_P@ -/* Define to 1 if strings.h declares `ffs' */ -#cmakedefine STRINGS_H_DECLARES_FFS 1 - /* Define to 1 if sys/ethernet.h declares `ether_hostton' */ #cmakedefine SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON 1 diff --git a/configure.ac b/configure.ac index 1be40a46..8341a2ce 100644 --- a/configure.ac +++ b/configure.ac @@ -243,27 +243,6 @@ if test $needstrtok_r = yes; then AC_LIBOBJ([strtok_r]) fi -# -# Do we have ffs(), and is it declared in ? -# -AC_CHECK_FUNCS(ffs) -if test "$ac_cv_func_ffs" = yes; then - # - # We have ffs(); is it declared in ? - # - # This test fails if we don't have or if we do - # but it doesn't declare ffs(). - # - AC_CHECK_DECL(ffs, - [ - AC_DEFINE(STRINGS_H_DECLARES_FFS, 1, - [Define to 1 if strings.h declares `ffs']) - ],, - [ -#include - ]) -fi - # # Do this before checking for ether_hostton(), as it's a # "getaddrinfo()-ish function". diff --git a/optimize.c b/optimize.c index d60ffa0c..89844411 100644 --- a/optimize.c +++ b/optimize.c @@ -139,49 +139,15 @@ lowest_set_bit(int mask) abort(); /* mask is zero */ return (u_int)bit; } -#elif defined(STRINGS_H_DECLARES_FFS) +#else /* - * A non-Windows OS that has and declares ffs() there (typically - * UN*X conforming to a sufficiently recent version of the Single UNIX - * Specification, but also Haiku). + * POSIX.1-2001 says ffs() is in . Every supported non-Windows OS + * (including Linux with musl libc and uclibc-ng) has the header and (except + * HP-UX) declares the function there. HP-UX declares the function in + * , which has already been included. */ #include #define lowest_set_bit(mask) ((u_int)(ffs((mask)) - 1)) -#elif defined(__hpux) - /* - * HP-UX 11i v3, which declares ffs() in , which we've already - * included. Place this branch after the branch, in case a later - * release of HP-UX makes the declaration available via the standard header. - */ - #define lowest_set_bit(mask) ((u_int)(ffs((mask)) - 1)) -#else -/* - * None of the above. - * Use a perfect-hash-function-based function. - */ -static u_int -lowest_set_bit(int mask) -{ - unsigned int v = (unsigned int)mask; - - static const u_int MultiplyDeBruijnBitPosition[32] = { - 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, - 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 - }; - - /* - * We strip off all but the lowermost set bit (v & ~v), - * and perform a minimal perfect hash on it to look up the - * number of low-order zero bits in a table. - * - * See: - * - * http://7ooo.mooo.com/text/ComputingTrailingZerosHOWTO.pdf - * - * http://supertech.csail.mit.edu/papers/debruijn.pdf - */ - return (MultiplyDeBruijnBitPosition[((v & -v) * 0x077CB531U) >> 27]); -} #endif /*