error_utils: move error helper to separate header

parent 9d3480da
...@@ -18,6 +18,7 @@ noinst_HEADERS = api_extensions.h \ ...@@ -18,6 +18,7 @@ noinst_HEADERS = api_extensions.h \
confile_utils.h \ confile_utils.h \
criu.h \ criu.h \
error.h \ error.h \
error_utils.h \
file_utils.h \ file_utils.h \
../include/netns_ifaddrs.h \ ../include/netns_ifaddrs.h \
initutils.h \ initutils.h \
...@@ -117,6 +118,7 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \ ...@@ -117,6 +118,7 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \
criu.c criu.h \ criu.c criu.h \
error.c error.h \ error.c error.h \
execute.c \ execute.c \
error_utils.h \
freezer.c \ freezer.c \
file_utils.c file_utils.h \ file_utils.c file_utils.h \
../include/netns_ifaddrs.c ../include/netns_ifaddrs.h \ ../include/netns_ifaddrs.c ../include/netns_ifaddrs.h \
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "commands_utils.h" #include "commands_utils.h"
#include "conf.h" #include "conf.h"
#include "config.h" #include "config.h"
#include "error_utils.h"
#include "log.h" #include "log.h"
#include "macro.h" #include "macro.h"
#include "mainloop.h" #include "mainloop.h"
......
/* 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 */
...@@ -700,43 +700,6 @@ enum { ...@@ -700,43 +700,6 @@ enum {
(b) = __tmp; \ (b) = __tmp; \
} while (0) } 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) \ #define min(x, y) \
({ \ ({ \
typeof(x) _min1 = (x); \ typeof(x) _min1 = (x); \
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <unistd.h> #include <unistd.h>
#include "macro.h" #include "macro.h"
#include "error_utils.h"
#define define_cleanup_function(type, cleaner) \ #define define_cleanup_function(type, cleaner) \
static inline void cleaner##_function(type *ptr) \ static inline void cleaner##_function(type *ptr) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment