4 * @brief Handy error handling for userspace.
6 * @author Taken from Linux Kernel (GPL2)
14 * Kernel pointers have redundant information, so we can use a
15 * scheme where we can return either an error code or a dentry
16 * pointer with the same return value.
18 * This should be a per-architecture thing, to allow different
19 * error and pointer decisions.
22 /* __builtin_expect(A, B) evaluates to A, but notifies the compiler that
23 the most likely value of A is B. This feature was added at some point
24 between 2.95 and 3.0. Let's use 3.0 as the lower bound for now. */
25 #define GCC_VERSION (__GNUC__ * 10000 \
26 + __GNUC_MINOR__ * 100 \
27 + __GNUC_PATCHLEVEL__)
28 #if (GCC_VERSION < 30000)
29 #define __builtin_expect(a, b) (a)
32 //#define __builtin_expect(expr, val) (expr)
33 #define likely(x) __builtin_expect(!!(x), 1)
34 #define unlikely(x) __builtin_expect(!!(x), 0)
36 #define MAX_ERRNO 4095
38 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
40 static inline void *ERR_PTR(long error
)
42 return (void *) error
;
45 static inline long PTR_ERR(const void *ptr
)
50 static inline long IS_ERR(const void *ptr
)
52 return IS_ERR_VALUE((unsigned long)ptr
);
55 #endif /* _LINUX_ERR_H */