Fix incorrect swap in mkomfs
[omfsprogs.git] / libomfs / bits.h
blob073b4d7b6864e740684b15a6b8a48e32798b0609
1 #ifndef _BITS_H
2 #define _BITS_H
4 static inline int test_bit(u8* buf, u64 offset)
6 return buf[offset >> 3] & (1<<(offset & 7));
9 static inline void init_bit(u8* buf, u64 offset, int value)
11 int mask = ((value & 1) << (offset & 7));
12 buf[offset >> 3] &= ~mask;
13 buf[offset >> 3] |= mask;
16 static inline void clear_bit(u8* buf, u64 offset)
18 buf[offset >> 3] &= ~(1 << (offset & 7));
21 static inline void set_bit(u8* buf, u64 offset)
23 buf[offset >> 3] |= 1 << (offset & 7);
26 static inline int is_power_of_two(int i)
28 return !(i & (i-1));
31 static inline int log_2(int i)
33 int count = 0;
35 for (i>>=1;i;i>>=1)
36 count++;
37 return count;
40 #endif