热门关键字:  ubuntu  分区  函数  Fedora  linux系统进程

当前位置 :| 主页>Linux教程>内核研究>

IS_ERR ERR_PTR PTR_ERR

来源: 作者: 时间:2007-10-22 Tag: 点击:
 查看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类型间转换.
最新评论共有 4 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册