Skip to content

Commit

Permalink
macro: add pointer error encoding support
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 26, 2021
1 parent bde8540 commit 75f08c8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/lxc/macro.h
Expand Up @@ -21,6 +21,8 @@
#include <sys/un.h>
#include <unistd.h>

#include "compiler.h"

#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
Expand Down Expand Up @@ -670,4 +672,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 */

0 comments on commit 75f08c8

Please sign in to comment.