DragonOS/kernel/common/err.h

46 lines
991 B
C
Raw Normal View History

#pragma once
#include <common/compiler.h>
#include <stdint.h>
#define MAX_ERRNO 4095
#define IS_ERR_VALUE(x) unlikely((x) >= (uint64_t)-MAX_ERRNO)
/**
* @brief errno
*
* @param ptr
* @return long 1 =>
* 0 =>
*/
static inline long __must_check IS_ERR(const void* ptr)
{
return IS_ERR_VALUE((uint64_t)ptr);
}
/**
* @brief errno或者为空
*
* @param ptr
* @return long 1 => NULL
* 0 => NULL
*/
static inline long __must_check IS_ERR_OR_NULL(const void* ptr)
{
return !ptr || IS_ERR_VALUE((uint64_t)ptr);
}
2022-09-30 07:30:50 +00:00
/**
* @brief
*
* @param error
* @return void*
*/
static inline void* __must_check ERR_PTR(long error)
{
return (void*)(error);
}
static inline long __must_check PTR_ERR(void * ptr)
{
return (long)ptr;
}