]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Remove our internal ffs32 and just use bitops.h
authorRoy Marples <roy@marples.name>
Fri, 29 Jan 2016 11:31:54 +0000 (11:31 +0000)
committerRoy Marples <roy@marples.name>
Fri, 29 Jan 2016 11:31:54 +0000 (11:31 +0000)
compat/bitops.h [moved from compat/ffs64.h with 54% similarity]
configure
dhcp6.c
ipv6.c

similarity index 54%
rename from compat/ffs64.h
rename to compat/bitops.h
index a00fd766bee1e8734052c575b7d071e5f195d172..ac0efc80798674f64d4a0d7c96ad7d8cded34bca 100644 (file)
@@ -1,4 +1,4 @@
-/*      $NetBSD: bitops.h,v 1.11 2012/12/07 02:27:58 christos Exp $     */
+/*     $NetBSD: bitops.h,v 1.11 2012/12/07 02:27:58 christos Exp $     */
 
 /*-
  * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef COMPAT_FFS64
-#define COMPAT_FFS64
+#ifndef COMPAT_BITOPS_H
+#define COMPAT_BITOPS_H
 
-#include <stdint.h>
+#include <sys/stdint.h>
+#include "../common.h"
 
-inline static int
+/*
+ * Find First Set functions
+ */
+#ifndef ffs32
+static inline int __unused
+ffs32(uint32_t _n)
+{
+       int _v;
+
+       if (!_n)
+               return 0;
+
+       _v = 1;
+       if ((_n & 0x0000FFFFU) == 0) {
+               _n >>= 16;
+               _v += 16;
+       }
+       if ((_n & 0x000000FFU) == 0) {
+               _n >>= 8;
+               _v += 8;
+       }
+       if ((_n & 0x0000000FU) == 0) {
+               _n >>= 4;
+               _v += 4;
+       }
+       if ((_n & 0x00000003U) == 0) {
+               _n >>= 2;
+               _v += 2;
+       }
+       if ((_n & 0x00000001U) == 0) {
+               _n >>= 1;
+               _v += 1;
+       }
+       return _v;
+}
+#endif
+
+#ifndef ffs64
+static inline int __unused
 ffs64(uint64_t _n)
 {
        int _v;
@@ -69,5 +108,81 @@ ffs64(uint64_t _n)
        }
        return _v;
 }
+#endif
 
+/*
+ * Find Last Set functions
+ */
+#ifndef fls32
+static __inline int __unused
+fls32(uint32_t _n)
+{
+       int _v;
+
+       if (!_n)
+               return 0;
+
+       _v = 32;
+       if ((_n & 0xFFFF0000U) == 0) {
+               _n <<= 16;
+               _v -= 16;
+       }
+       if ((_n & 0xFF000000U) == 0) {
+               _n <<= 8;
+               _v -= 8;
+       }
+       if ((_n & 0xF0000000U) == 0) {
+               _n <<= 4;
+               _v -= 4;
+       }
+       if ((_n & 0xC0000000U) == 0) {
+               _n <<= 2;
+               _v -= 2;
+       }
+       if ((_n & 0x80000000U) == 0) {
+               _n <<= 1;
+               _v -= 1;
+       }
+       return _v;
+}
 #endif
+
+#ifndef fls64
+static int __unused
+fls64(uint64_t _n)
+{
+       int _v;
+
+       if (!_n)
+               return 0;
+
+       _v = 64;
+       if ((_n & 0xFFFFFFFF00000000ULL) == 0) {
+               _n <<= 32;
+               _v -= 32;
+       }
+       if ((_n & 0xFFFF000000000000ULL) == 0) {
+               _n <<= 16;
+               _v -= 16;
+       }
+       if ((_n & 0xFF00000000000000ULL) == 0) {
+               _n <<= 8;
+               _v -= 8;
+       }
+       if ((_n & 0xF000000000000000ULL) == 0) {
+               _n <<= 4;
+               _v -= 4;
+       }
+       if ((_n & 0xC000000000000000ULL) == 0) {
+               _n <<= 2;
+               _v -= 2;
+       }
+       if ((_n & 0x8000000000000000ULL) == 0) {
+               _n <<= 1;
+               _v -= 1;
+       }
+       return _v;
+}
+#endif
+
+#endif /* COMPAT_BITOPS_H_ */
index 0ad1f77b13bf5673a4baea902bbfc9c527779282..24cac8f040b5719ed8af3b9627517a3129c681de 100755 (executable)
--- a/configure
+++ b/configure
@@ -1002,9 +1002,7 @@ EOF
        rm -f _ffs64.c _ffs64
 fi
 if [ "$FFS64" = yes ]; then
-       echo "CPPFLAGS+=        -DHAVE_SYS_BITOPS_H" >>$CONFIG_MK
-else
-       echo "#include          \"compat/ffs64.h\"" >>$CONFIG_H
+       echo "#define HAVE_SYS_BITOPS_H" >>$CONFIG_H
 fi
 
 if [ -z "$MD5" ]; then
diff --git a/dhcp6.c b/dhcp6.c
index 9abe78e78f0013b9fc38fc94e9d61d7992ec5ced..667815160bf4b77dd64a72d23f50ce080d09d3e4 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
 #include "ipv6nd.h"
 #include "script.h"
 
+#ifdef HAVE_SYS_BITOPS_H
+#include <sys/bitops.h>
+#else
+#include "compat/bitops.h"
+#endif
+
 #ifndef __UNCONST
 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
 #endif
@@ -374,40 +380,6 @@ dhcp6_findselfsla(struct interface *ifp, const uint8_t *iaid)
        return NULL;
 }
 
-
-#ifndef ffs32
-static int
-ffs32(uint32_t n)
-{
-       int v;
-
-       if (!n)
-               return 0;
-
-       v = 1;
-       if ((n & 0x0000FFFFU) == 0) {
-               n >>= 16;
-               v += 16;
-       }
-       if ((n & 0x000000FFU) == 0) {
-               n >>= 8;
-               v += 8;
-       }
-       if ((n & 0x0000000FU) == 0) {
-               n >>= 4;
-               v += 4;
-       }
-       if ((n & 0x00000003U) == 0) {
-               n >>= 2;
-               v += 2;
-       }
-       if ((n & 0x00000001U) == 0)
-               v += 1;
-
-       return v;
-}
-#endif
-
 static int
 dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
     const struct ipv6_addr *prefix, const struct if_sla *sla, struct if_ia *ia)
diff --git a/ipv6.c b/ipv6.c
index 7e77b966984c93b069dd6b9ba3f3b2eafd82e9d5..b381df329dda074c97b44e42643888b7e921dd06 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -39,6 +39,8 @@
 
 #ifdef HAVE_SYS_BITOPS_H
 #include <sys/bitops.h>
+#else
+#include "compat/bitops.h"
 #endif
 
 #ifdef BSD