~ubuntu-branches/ubuntu/vivid/tgt/vivid-proposed

« back to all changes in this revision

Viewing changes to usr/util.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-14 12:05:08 UTC
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: package-import@ubuntu.com-20140114120508-rc9p28cdrid5fa4x
Tags: upstream-1.0.43
ImportĀ upstreamĀ versionĀ 1.0.43

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "be_byteshift.h"
20
20
 
21
21
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
 
22
#define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
22
23
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
23
24
#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
24
25
 
158
159
#define str_to_int_gt(str, val, minv)                   \
159
160
({                                                      \
160
161
        int ret = str_to_int(str, val);                 \
161
 
        if (!ret && (val < minv))                       \
 
162
        if (!ret && (val <= minv))                      \
162
163
                ret = ERANGE;                           \
163
164
        ret;                                            \
164
165
})
176
177
#define str_to_int_lt(str, val, maxv)                   \
177
178
({                                                      \
178
179
        int ret = str_to_int(str, val);                 \
179
 
        if (!ret && (val > maxv))                       \
 
180
        if (!ret && (val >= maxv))                      \
180
181
                ret = ERANGE;                           \
181
182
        ret;                                            \
182
183
})
214
215
#ifdef FALLOC_FL_PUNCH_HOLE
215
216
        if (fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
216
217
                        offset, length) == 0)
217
 
                return 0; 
 
218
                return 0;
218
219
#endif
219
220
        return -1;
220
221
}
221
222
 
 
223
#define BITS_PER_LONG __WORDSIZE
 
224
#define BITS_PER_BYTE           8
 
225
#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 
226
 
 
227
static inline void set_bit(int nr, unsigned long *addr)
 
228
{
 
229
        addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
 
230
}
 
231
 
 
232
static inline void clear_bit(int nr, unsigned long *addr)
 
233
{
 
234
        addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
 
235
}
 
236
 
 
237
static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
 
238
{
 
239
        return ((1UL << (nr % BITS_PER_LONG)) &
 
240
                (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
 
241
}
222
242
 
223
243
#endif