查看2.6 include/linux/err.h
/*
* kernel pointers have redundant information, so we can use a
* scheme where we can return either an error code or a dentry
* pointer with the same return value.
*
* this should be a per-architecture thing, to allow different
* error and pointer decisions.
*/
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 unlikely((unsigned long)ptr > (unsigned long)-1000l);
}
|
使用eg:
int err;
void *perr;
err = -enomem;
perr = err_ptr(err);
printk("err.%d perr.%p \n", err, perr);
if (is_err(perr))
{
printk("ptr_err changed ==> err.%d", (int)ptr_err(perr));
}
|
主要用在错误指针同错误int类型间转换.
阅读(3056) | 评论(0) | 转发(0) |