http://linux-ntfs.sourceforge.net/snapshots/ntfsprogs-200307311516.tar.bz2
[ntfsprogs.git] / libntfs / compat.c
1 /*
2  * compat.c - Tweaks for Windows compatability
3  *
4  * Copyright (c) 2002 Richard Russon
5  * Copyright (c) 2002 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 Linux-NTFS
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 #ifdef WINDOWS
24
25 #include "compat.h"
26
27 // TODO: Add check for FFS in the configure script... (AIA)
28 #ifndef HAVE_FFS
29 int ffs(int x)
30 {
31         int r = 1;
32
33         if (!x)
34                 return 0;
35         if (!(x & 0xffff)) {
36                 x >>= 16;
37                 r += 16;
38         }
39         if (!(x & 0xff)) {
40                 x >>= 8;
41                 r += 8;
42         }
43         if (!(x & 0xf)) {
44                 x >>= 4;
45                 r += 4;
46         }
47         if (!(x & 3)) {
48                 x >>= 2;
49                 r += 2;
50         }
51         if (!(x & 1)) {
52                 x >>= 1;
53                 r += 1;
54         }
55         return r;
56 }
57 #endif /* HAVE_FFS */
58
59 #endif /* WINDOWS */
60