errno 定義於 <errno.h>,錯誤宏分佈在 /usr/include/asm-generic/errno-base.h (1-34) 和 errno.h (35-132)。
#include <errno.h>
#include <string.h>
#include <stdio.h>
int main() {
for (int i = 0; i < 140; ++i) {
errno = i;
printf("errno %d :\t\t%s\n", i, strerror(errno));
}
return 0;
}
| errno | 宏 | 描述 |
|---|---|---|
| 1 | EPERM | Operation not permitted |
| 2 | ENOENT | No such file or directory |
| 11 | EAGAIN | Resource temporarily unavailable |
| 12 | ENOMEM | Cannot allocate memory |
| 13 | EACCES | Permission denied |
| 22 | EINVAL | Invalid argument |
| 24 | EMFILE | Too many open files |
| 28 | ENOSPC | No space left on device |
| 32 | EPIPE | Broken pipe |
| 98 | EADDRINUSE | Address already in use |
| 104 | ECONNRESET | Connection reset by peer |
| 110 | ETIMEDOUT | Connection timed out |
| 111 | ECONNREFUSED | Connection refused |
| 113 | EHOSTUNREACH | No route to host |
完整列表見內核頭文件源碼附錄。