]> The Tcpdump Group git mirrors - libpcap/commitdiff
When necessary, trust the OS to implement ffs(). 1306/head
authorDenis Ovsienko <[email protected]>
Thu, 28 Mar 2024 11:32:41 +0000 (11:32 +0000)
committerDenis Ovsienko <[email protected]>
Thu, 28 Mar 2024 11:56:38 +0000 (11:56 +0000)
Eliminate some dead code and two more build-time checks in Autoconf and
CMake.

CHANGES
CMakeLists.txt
cmakeconfig.h.in
configure.ac
optimize.c

diff --git a/CHANGES b/CHANGES
index 45d51da098fc5e79aa937d120f9b66fc53ebf26a..d4701dfff0c57cb0c836d8ef4c6ebf9cb370a978 100644 (file)
--- 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.
index af0ae3ab14c1542b40bf2b54244bee4da370d92b..1c47169d4ac5e2455d35512d53ce4949eba79dd4 100644 (file)
@@ -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 <strings.h>?
-#
-check_function_exists(ffs HAVE_FFS)
-if(HAVE_FFS)
-    #
-    # OK, we have ffs().  Is it declared in <strings.h>?
-    #
-    # This test fails if we don't have <strings.h> 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
index 140d14b977600c51d6b737048e295ad43496125d..a0a11335cc8486dea9f53c9cdcda72ad0631a81e 100644 (file)
 /* 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
 
index 1be40a4671da906352b95b1d1d6d5ffbe03174d1..8341a2ceeb7283458f674dc167ceb7b79dcd3fd7 100644 (file)
@@ -243,27 +243,6 @@ if test $needstrtok_r = yes; then
        AC_LIBOBJ([strtok_r])
 fi
 
-#
-# Do we have ffs(), and is it declared in <strings.h>?
-#
-AC_CHECK_FUNCS(ffs)
-if test "$ac_cv_func_ffs" = yes; then
-       #
-       # We have ffs(); is it declared in <strings.h>?
-       #
-       # This test fails if we don't have <strings.h> 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 <strings.h>
-           ])
-fi
-
 #
 # Do this before checking for ether_hostton(), as it's a
 # "getaddrinfo()-ish function".
index d60ffa0c7a1eada146f1f8601f789a72b7942403..89844411ed99b06543849c20cdc7ab2d7d9161b0 100644 (file)
@@ -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 <strings.h> 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 <strings.h>.  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
+   * <string.h>, which has already been included.
    */
   #include <strings.h>
   #define lowest_set_bit(mask) ((u_int)(ffs((mask)) - 1))
-#elif defined(__hpux)
-  /*
-   * HP-UX 11i v3, which declares ffs() in <string.h>, which we've already
-   * included.  Place this branch after the <strings.h> 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
 
 /*