From: Christian Brauner Date: Sat, 20 Feb 2021 00:30:33 +0000 (+0100) Subject: macro: add pointer error encoding support X-Git-Tag: lxc-5.0.0~274^2~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=844d929d2e92a7b19b1b4f93ea95916284f0a14a;p=thirdparty%2Flxc.git macro: add pointer error encoding support Signed-off-by: Christian Brauner --- diff --git a/src/lxc/macro.h b/src/lxc/macro.h index e900df281..604b329e3 100644 --- a/src/lxc/macro.h +++ b/src/lxc/macro.h @@ -21,6 +21,8 @@ #include #include +#include "compiler.h" + #ifndef PATH_MAX #define PATH_MAX 4096 #endif @@ -698,4 +700,41 @@ enum { (b) = __tmp; \ } while (0) +#define MAX_ERRNO 4095 + +#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) + +static inline void *ERR_PTR(long error) +{ + return (void *)error; +} + +static inline long PTR_ERR(const void *ptr) +{ + return (long)ptr; +} + +static inline long IS_ERR(const void *ptr) +{ + return IS_ERR_VALUE((unsigned long)ptr); +} + +static inline long IS_ERR_OR_NULL(const void *ptr) +{ + return !ptr || IS_ERR_VALUE((unsigned long)ptr); +} + +static inline void *ERR_CAST(const void *ptr) +{ + return (void *)ptr; +} + +static inline int PTR_RET(const void *ptr) +{ + if (IS_ERR(ptr)) + return PTR_ERR(ptr); + else + return 0; +} + #endif /* __LXC_MACRO_H */