xref: /haiku/src/add-ons/kernel/file_systems/ntfs/libntfs/compat.c (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /**
2  * compat.c - Tweaks for Windows compatibility
3  *
4  * Copyright (c) 2002 Richard Russon
5  * Copyright (c) 2002-2004 Anton Altaparmakov
6  *
7  * This program/include file is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program/include file is distributed in the hope that it will be
13  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program (in the main directory of the NTFS-3G
19  * distribution in the file COPYING); if not, write to the Free Software
20  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22 
23 #if defined(WINDOWS) || defined(__BEOS__) || defined (__HAIKU__)
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 
29 #include "compat.h"
30 
31 /* TODO: Add check for FFS in the configure script... (AIA) */
32 
33 #ifndef HAVE_FFS
34 /**
35  * ffs - Find the first set bit in an int
36  * @x:
37  *
38  * Description...
39  *
40  * Returns:
41  */
42 int ffs(int x)
43 {
44 	int r = 1;
45 
46 	if (!x)
47 		return 0;
48 	if (!(x & 0xffff)) {
49 		x >>= 16;
50 		r += 16;
51 	}
52 	if (!(x & 0xff)) {
53 		x >>= 8;
54 		r += 8;
55 	}
56 	if (!(x & 0xf)) {
57 		x >>= 4;
58 		r += 4;
59 	}
60 	if (!(x & 3)) {
61 		x >>= 2;
62 		r += 2;
63 	}
64 	if (!(x & 1)) {
65 		x >>= 1;
66 		r += 1;
67 	}
68 	return r;
69 }
70 #endif /* HAVE_FFS */
71 
72 #endif /* defined(WINDOWS) || defined(__BEOS__) || defined (__HAIKU__) */
73 
74