Whamcloud - gitweb
0f808a26bfa76c3694379214c84c2a0057c6c2d0
[fs/lustre-release.git] / libcfs / include / libcfs / darwin / darwin-utils.h
1 #ifndef __LIBCFS_DARWIN_UTILS_H__
2 #define __LIBCFS_DARWIN_UTILS_H__
3
4 #ifndef __LIBCFS_LIBCFS_H__
5 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
6 #endif
7
8 #include <sys/random.h> 
9
10 #ifdef __KERNEL__
11 inline int isspace(char c);
12 char *strpbrk(const char *cs, const char *ct);
13 char * strsep(char **s, const char *ct);
14 size_t strnlen(const char * s, size_t count);
15 char * strstr(const char *in, const char *str);
16 char * strrchr(const char *p, int ch);
17 char * ul2dstr(unsigned long address, char *buf, int len);
18
19 #define simple_strtol(a1, a2, a3)               strtol(a1, a2, a3)
20 #define simple_strtoul(a1, a2, a3)              strtoul(a1, a2, a3)
21 #define simple_strtoll(a1, a2, a3)              strtoq(a1, a2, a3)
22 #define simple_strtoull(a1, a2, a3)             strtouq(a1, a2, a3)
23
24 #define test_bit(i, a)                          isset(a, i)
25 #define set_bit(i, a)                           setbit(a, i)
26 #define clear_bit(i, a)                         clrbit(a, i)
27
28 #define get_random_bytes(buf, len)              read_random(buf, len)
29
30 #endif  /* __KERNEL__ */
31
32 #ifndef min_t
33 #define min_t(type,x,y) \
34         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
35 #endif
36 #ifndef max_t
37 #define max_t(type,x,y) \
38         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
39 #endif
40
41 #define do_div(n,base)                          \
42         ({                                      \
43          __u64 __n = (n);                       \
44          __u32 __base = (base);                 \
45          __u32 __mod;                           \
46                                                 \
47          __mod = __n % __base;                  \
48          n = __n / __base;                      \
49          __mod;                                 \
50          })
51
52 #define NIPQUAD(addr)                   \
53         ((unsigned char *)&addr)[0],    \
54         ((unsigned char *)&addr)[1],    \
55         ((unsigned char *)&addr)[2],    \
56         ((unsigned char *)&addr)[3]
57
58 #define HIPQUAD NIPQUAD
59
60 #ifndef LIST_CIRCLE
61 #define LIST_CIRCLE(elm, field)                                 \
62         do {                                                    \
63                 (elm)->field.le_prev = &(elm)->field.le_next;   \
64         } while (0)
65 #endif
66
67 #endif /* __XNU_UTILS_H__ */