有时可以知道错误的数值,但是如果不知道对应于那个宏定义,也很难知道这个错误描述的是什么。我平时这两种方法来确定:在内核源码中搜索和查看头文件。 在内核源码中搜索一般都可以搜到,而且使用source insight的话也很方便,不多说了。当然更多的时候还是看头文件,因为一般的错误在/usr/include/asm-generic/errno-base.h和/usr/include/asm-generic/errno.h这个两个头文件中都可以找到,在/usr/include/bits/errno.h头文件中也有,但是很少。我写这篇的目的就是给哪些比较懒的同学,当然也给自己,下面我会贴出头文件中定义,这样便于查阅:
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */