Implement vfs layer
[thunix.git] / include / err.h
blobd178462e53146bad10808bbc8bb505e1f3b51ec2
1 /* From linux kernle source code */
3 #ifndef _LINUX_ERR_H
4 #define _LINUX_ERR_H
6 #include <errno.h>
8 /*
9 * Kernel pointers have redundant information, so we can use a
10 * scheme where we can return either an error code or a dentry
11 * pointer with the same return value.
13 * This should be a per-architecture thing, to allow different
14 * error and pointer decisions.
16 #define MAX_ERRNO 4095
19 #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO)
21 static inline void *ERR_PTR(long error)
23 return (void *) error;
26 static inline long PTR_ERR(const void *ptr)
28 return (long) ptr;
31 static inline long IS_ERR(const void *ptr)
33 return IS_ERR_VALUE((unsigned long)ptr);
36 static inline long IS_ERR_OR_NULL(const void *ptr)
38 return !ptr || IS_ERR_VALUE((unsigned long)ptr);
41 /**
42 * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
43 * @ptr: The pointer to cast.
45 * Explicitly cast an error-valued pointer to another pointer type in such a
46 * way as to make it clear that's what's going on.
48 static inline void *ERR_CAST(const void *ptr)
50 /* cast away the const */
51 return (void *) ptr;
55 #endif /* _LINUX_ERR_H */