开发者

Troubles with errno.h

I'm working with Rad Hat 8.0, trying to make changes to开发者_JAVA技巧 the kernel, and I'm at the compilation stage. I have a header in include/linux where I define wrapper functions, and they use errno. I included errno.h using #include <errno.h>. When I try to compile, it tells me "errno.h no such file or directory". When I try #include <linux/errno.h> it finds it but complains that I did not declare errno the variable before use. I looked at errno.h and it really doesn't have it declared, which is confusing because I was under the impression that this is where it is defined.

Am I looking in the wrong places? How do I make use of errno?


For kernel code, #include <linux/errno.h>.

The extern declaration for errno is in #include <linux/unistd.h>.


In accordance to this, errno variable is set automaticly when you return a negative value.

Example:

asmlinkage long sys_foo() {
    ...
    if(error)
        return -(errorcode);
    ...
}

In this case the returning result in userspace will be -1 and errno variable will have value of errorcode.


errno is defined as an extern in

/usr/src/lib/linux/errno.c

you have to compile this file with yours

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜