[CRIU] [PATCH 5/6] util: encode and decode errno into pointer

Andrey Vagin avagin at openvz.org
Wed Mar 27 15:51:02 EDT 2013


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/util.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/include/util.h b/include/util.h
index 56e3c25..aceb07d 100644
--- a/include/util.h
+++ b/include/util.h
@@ -305,4 +305,29 @@ static inline bool dir_dots(struct dirent *de)
 
 extern int read_fd_link(int lfd, char *buf, size_t size);
 
+
+#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);
+}
+
 #endif /* __CR_UTIL_H__ */
-- 
1.7.11.7



More information about the CRIU mailing list