]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
macro: add pointer error encoding support
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 20 Feb 2021 00:30:33 +0000 (01:30 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 20 Feb 2021 00:36:00 +0000 (01:36 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/macro.h

index e900df281115326782b271cc308984fb6a776c9e..604b329e36b28cc6042c525888bb0650a4ef0f38 100644 (file)
@@ -21,6 +21,8 @@
 #include <sys/un.h>
 #include <unistd.h>
 
+#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 */