mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 22:35:33 +00:00
headers: Add err.h header
Instead of bloating util.h lets move ERR_ helpers to own err.h header. This allow to reuse it where needed without util.h inclusion. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
fd3f33f5d2
commit
1525447752
53
include/err.h
Normal file
53
include/err.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Adopted from linux kernel
|
||||
*/
|
||||
#ifndef __CR_ERR_H__
|
||||
#define __CR_ERR_H__
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/*
|
||||
* The address of a block returned by malloc or realloc in GNU
|
||||
* systems is always a multiple of eight (or sixteen on 64-bit systems).
|
||||
*
|
||||
* Thus we may encode error number in low bits.
|
||||
*/
|
||||
#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)
|
||||
{
|
||||
/* cast away the const */
|
||||
return (void *)ptr;
|
||||
}
|
||||
|
||||
static inline int PTR_RET(const void *ptr)
|
||||
{
|
||||
if (IS_ERR(ptr))
|
||||
return PTR_ERR(ptr);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __CR_ERR_H__ */
|
@@ -16,6 +16,7 @@
|
||||
#include "asm/types.h"
|
||||
#include "bug.h"
|
||||
#include "log.h"
|
||||
#include "err.h"
|
||||
|
||||
#include "protobuf/vma.pb-c.h"
|
||||
|
||||
@@ -305,29 +306,4 @@ 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__ */
|
||||
|
Reference in New Issue
Block a user