Rev 1968 | Rev 2005 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1968 | Rev 1970 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | 9 | ||
10 | #include |
10 | #include |
11 | #include |
11 | #include |
12 | #include |
12 | #include |
- | 13 | #include |
|
Line 13... | Line 14... | ||
13 | #include |
14 | #include |
14 | 15 | ||
15 | #define USHRT_MAX ((u16)(~0U)) |
16 | #define USHRT_MAX ((u16)(~0U)) |
16 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
17 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
Line 52... | Line 53... | ||
52 | #define KERN_ERR "<3>" /* error conditions */ |
53 | #define KERN_ERR "<3>" /* error conditions */ |
53 | #define KERN_WARNING "<4>" /* warning conditions */ |
54 | #define KERN_WARNING "<4>" /* warning conditions */ |
54 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
55 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
55 | #define KERN_INFO "<6>" /* informational */ |
56 | #define KERN_INFO "<6>" /* informational */ |
56 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
57 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
- | 58 | extern const char hex_asc[]; |
|
- | 59 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
|
- | 60 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
|
- | 61 | ||
- | 62 | static inline char *pack_hex_byte(char *buf, u8 byte) |
|
- | 63 | { |
|
- | 64 | *buf++ = hex_asc_hi(byte); |
|
- | 65 | *buf++ = hex_asc_lo(byte); |
|
- | 66 | return buf; |
|
- | 67 | } |
|
- | 68 | ||
- | 69 | extern int hex_to_bin(char ch); |
|
- | 70 | extern void hex2bin(u8 *dst, const char *src, size_t count); |
|
- | 71 | ||
Line 57... | Line 72... | ||
57 | 72 | ||
Line 58... | Line 73... | ||
58 | //int printk(const char *fmt, ...); |
73 | //int printk(const char *fmt, ...); |
Line 75... | Line 90... | ||
75 | typeof(x) _max1 = (x); \ |
90 | typeof(x) _max1 = (x); \ |
76 | typeof(y) _max2 = (y); \ |
91 | typeof(y) _max2 = (y); \ |
77 | (void) (&_max1 == &_max2); \ |
92 | (void) (&_max1 == &_max2); \ |
78 | _max1 > _max2 ? _max1 : _max2; }) |
93 | _max1 > _max2 ? _max1 : _max2; }) |
Line -... | Line 94... | ||
- | 94 | ||
- | 95 | #define min3(x, y, z) ({ \ |
|
- | 96 | typeof(x) _min1 = (x); \ |
|
- | 97 | typeof(y) _min2 = (y); \ |
|
- | 98 | typeof(z) _min3 = (z); \ |
|
- | 99 | (void) (&_min1 == &_min2); \ |
|
- | 100 | (void) (&_min1 == &_min3); \ |
|
- | 101 | _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \ |
|
- | 102 | (_min2 < _min3 ? _min2 : _min3); }) |
|
- | 103 | ||
- | 104 | #define max3(x, y, z) ({ \ |
|
- | 105 | typeof(x) _max1 = (x); \ |
|
- | 106 | typeof(y) _max2 = (y); \ |
|
- | 107 | typeof(z) _max3 = (z); \ |
|
- | 108 | (void) (&_max1 == &_max2); \ |
|
- | 109 | (void) (&_max1 == &_max3); \ |
|
- | 110 | _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \ |
|
- | 111 | (_max2 > _max3 ? _max2 : _max3); }) |
|
- | 112 | ||
- | 113 | /** |
|
- | 114 | * min_not_zero - return the minimum that is _not_ zero, unless both are zero |
|
- | 115 | * @x: value1 |
|
- | 116 | * @y: value2 |
|
- | 117 | */ |
|
- | 118 | #define min_not_zero(x, y) ({ \ |
|
- | 119 | typeof(x) __x = (x); \ |
|
- | 120 | typeof(y) __y = (y); \ |
|
- | 121 | __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) |
|
- | 122 | ||
- | 123 | /** |
|
- | 124 | * clamp - return a value clamped to a given range with strict typechecking |
|
- | 125 | * @val: current value |
|
- | 126 | * @min: minimum allowable value |
|
- | 127 | * @max: maximum allowable value |
|
- | 128 | * |
|
- | 129 | * This macro does strict typechecking of min/max to make sure they are of the |
|
- | 130 | * same type as val. See the unnecessary pointer comparisons. |
|
- | 131 | */ |
|
- | 132 | #define clamp(val, min, max) ({ \ |
|
- | 133 | typeof(val) __val = (val); \ |
|
- | 134 | typeof(min) __min = (min); \ |
|
- | 135 | typeof(max) __max = (max); \ |
|
- | 136 | (void) (&__val == &__min); \ |
|
- | 137 | (void) (&__val == &__max); \ |
|
- | 138 | __val = __val < __min ? __min: __val; \ |
|
- | 139 | __val > __max ? __max: __val; }) |
|
79 | 140 | ||
80 | /* |
141 | /* |
81 | * ..and if you can't take the strict |
142 | * ..and if you can't take the strict |
82 | * types, you can specify one yourself. |
143 | * types, you can specify one yourself. |
83 | * |
144 | * |
Line 110... | Line 171... | ||
110 | if (n != 0 && size > ULONG_MAX / n) |
171 | if (n != 0 && size > ULONG_MAX / n) |
111 | return NULL; |
172 | return NULL; |
112 | return kzalloc(n * size, 0); |
173 | return kzalloc(n * size, 0); |
113 | } |
174 | } |
Line 114... | Line -... | ||
114 | - | ||
115 | extern const char hex_asc[]; |
- | |
116 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
- | |
117 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
- | |
118 | - | ||
119 | static inline char *pack_hex_byte(char *buf, u8 byte) |
- | |
120 | { |
- | |
121 | *buf++ = hex_asc_hi(byte); |
- | |
122 | *buf++ = hex_asc_lo(byte); |
- | |
123 | return buf; |
- | |
124 | } |
- | |
Line 125... | Line 175... | ||
125 | 175 | ||
Line 126... | Line 176... | ||
126 | 176 |