-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.h
65 lines (54 loc) · 1.14 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* utils.h -- various utilities */
#ifndef BASE_UTILS_H
#define BASE_UTILS_H
/* When on RISC OS, bring OSLib's types in. */
#ifdef __riscos
#include "oslib/types.h"
#endif
/**
* Returns the number of elements in the specified array.
*/
#ifndef NELEMS
#define NELEMS(a) ((int) (sizeof(a) / sizeof((a)[0])))
#endif
/**
* Divide while rounding upwards.
*/
#define DIVIDE_ROUNDING_UP(n, m) (((n) + (m) - 1) / (m))
/**
* Return the minimum of (a,b).
*/
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
/**
* Return the maximum of (a,b).
*/
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
/**
* Return 'a' clamped to the range [b..c].
*/
#define CLAMP(a,b,c) MIN(MAX(a,b),c)
/**
* Suppress warnings about unused variables.
*/
#ifndef NOT_USED
#define NOT_USED(x) ((x) = (x))
#endif
/**
* Inlining.
*/
#ifdef _WIN32
#define INLINE __inline
#else
#define INLINE __inline__
#endif
/**
* Hints to compiler of probable execution path.
*/
#ifdef __GNUC__
#define likely(expr) __builtin_expect(!!(expr), 1)
#define unlikely(expr) __builtin_expect(!!(expr), 0)
#else
#define likely(expr) (expr)
#define unlikely(expr) (expr)
#endif
#endif /* BASE_UTILS_H */