Adapt libs/pbd/ffs.cc to be buildable with MSVC
authorJohn Emmas <johne53@tiscali.co.uk>
Thu, 18 Jul 2013 11:08:34 +0000 (12:08 +0100)
committerJohn Emmas <johne53@tiscali.co.uk>
Thu, 18 Jul 2013 11:08:34 +0000 (12:08 +0100)
libs/pbd/ffs.cc

index 0a61969e8aad77c8fbec2a4a85eb054858b2ba0b..557504f14eb887bf5a10ca7a6c2093c05b706614 100644 (file)
 
 #include "pbd/ffs.h"
 
+#ifndef COMPILER_MSVC
 #include <strings.h>
+#endif
 
 namespace PBD {
 int
 ffs (int x)
 {
-#if defined(WIN32) && defined(__GNUC__)
+#if defined (COMPILER_MINGW)
        return __builtin_ffs(x);
+#elif defined (COMPILER_MSVC)
+       unsigned long index;
+#ifdef WIN64   
+       if (0 != _BitScanForward64(&index, (__int64)x))
+#else
+       if (0 != _BitScanForward(&index, (unsigned long)x))
+#endif
+               index++;    // Make the result 1-based
+       else
+               index = 0;  // All bits were zero
+
+       return (int)index;
 #else
        return ::ffs(x);
 #endif