From: Christian Brauner Date: Wed, 24 Feb 2021 08:16:09 +0000 (+0100) Subject: error_utils: move error helper to separate header X-Git-Tag: lxc-5.0.0~269^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38fa7e479cea516d2cf303bbe8f3a8f88ea2a3c9;p=thirdparty%2Flxc.git error_utils: move error helper to separate header Signed-off-by: Christian Brauner --- diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index fb18e4f1b..634396fa8 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -18,6 +18,7 @@ noinst_HEADERS = api_extensions.h \ confile_utils.h \ criu.h \ error.h \ + error_utils.h \ file_utils.h \ ../include/netns_ifaddrs.h \ initutils.h \ @@ -117,6 +118,7 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \ criu.c criu.h \ error.c error.h \ execute.c \ + error_utils.h \ freezer.c \ file_utils.c file_utils.h \ ../include/netns_ifaddrs.c ../include/netns_ifaddrs.h \ diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 3e057e54e..fd7c82561 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -40,6 +40,7 @@ #include "commands_utils.h" #include "conf.h" #include "config.h" +#include "error_utils.h" #include "log.h" #include "macro.h" #include "mainloop.h" diff --git a/src/lxc/error_utils.h b/src/lxc/error_utils.h new file mode 100644 index 000000000..e65086158 --- /dev/null +++ b/src/lxc/error_utils.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#ifndef __LXC_ERROR_UTILS_H +#define __LXC_ERROR_UTILS_H + +#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_ERROR_UTILS_H */ diff --git a/src/lxc/macro.h b/src/lxc/macro.h index c33480cc7..c98ca5900 100644 --- a/src/lxc/macro.h +++ b/src/lxc/macro.h @@ -700,43 +700,6 @@ 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; -} - #define min(x, y) \ ({ \ typeof(x) _min1 = (x); \ diff --git a/src/lxc/memory_utils.h b/src/lxc/memory_utils.h index 143cb8a84..7e4d0541f 100644 --- a/src/lxc/memory_utils.h +++ b/src/lxc/memory_utils.h @@ -11,6 +11,7 @@ #include #include "macro.h" +#include "error_utils.h" #define define_cleanup_function(type, cleaner) \ static inline void cleaner##_function(type *ptr) \