查看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类型间转换.