1,Linux系统
以GLibc作为C标准库代表,Linux作为操作系统代表,来确定errno的定义。
当使用C标准库的errno.h这个头文件时,其包含内容:
include/errno.h
#include <stdlib/errno.h>
// errno定义分情况:
// 1, 动态链接库
/* The dynamic linker uses its own private errno variable.
All access to errno inside the dynamic linker is serialized,
so a single (hidden) global variable is all it needs. */
# define errno rtld_errno
// 2, libc
# define errno __libc_errno
// 3, 其他情况, 使用线程修饰符
# define errno errno /* For #ifndef errno tests. */
extern __thread int errno attribute_tls_model_ie;
// 函数
# define __set_errno(val) (errno = (val)) // GLibc库里面都用这个函数来设置errno
stdlib/errno.h
#include <bits/errno.h>
// 下面这个是GNU才有
/* The full and simple forms of the name with which the program was
invoked. These variables are set up automatically at startup based on
the value of argv[0]. */
extern char *program_invocation_name;
extern char *program_invocation_short_name;
#include <bits/types/error_t.h>
bits/errno.h
// 这个是包含了Linux系统的头文件
# include <linux/errno.h>
/* Older Linux headers do not define these constants. */
# ifndef ENOTSUP
# define ENOTSUP EOPNOTSUPP
# endif
# ifndef ECANCELED
# define ECANCELED 125
# endif
# ifndef EOWNERDEAD
# define EOWNERDEAD 130
# endif
#ifndef ENOTRECOVERABLE
# define ENOTRECOVERABLE 131
# endif
# ifndef ERFKILL
# define ERFKILL 132
# endif
# ifndef EHWPOISON
# define EHWPOISON 133
# endif
#endif /* bits/errno.h. */
bits/types/error_t.h
typedef int error_t;
Linux系统的errno.h包含内容:
linux/errno.h
#include <uapi/linux/errno.h>
/*
* These should never be seen by user programs. To return one of ERESTART*
* codes, signal_pending() MUST be set. Note that ptrace can observe these
* at syscall exit tracing, but they will never be left for the debugged user
* process to see.
*/
#define ERESTARTSYS 512
#define ERESTARTNOINTR 513
#define ERESTARTNOHAND 514 /* restart if no handler.. */
#define ENOIOCTLCMD 515 /* No ioctl command */
#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
#define EPROBE_DEFER 517 /* Driver requests probe retry */
#define EOPENSTALE 518 /* open found a stale dentry */
#define ENOPARAM 519 /* Parameter not supported */
/* Defined for the NFSv3 protocol */
#define EBADHANDLE 521 /* Illegal NFS file handle */
#define ENOTSYNC 522 /* Update synchronization mismatch */
#define EBADCOOKIE 523 /* Cookie is stale */
#define ENOTSUPP 524 /* Operation is not supported */
#define ETOOSMALL 525 /* Buffer or request is too small */
#define ESERVERFAULT 526 /* An untranslatable error occurred */
#define EBADTYPE 527 /* Type not supported by server */
#define EJUKEBOX 528 /* Request initiated, but will not complete before timeout */
#define EIOCBQUEUED 529 /* iocb queued, will get completion event */
#define ERECALLCONFLICT 530 /* conflict with recalled state */
#define ENOGRACE 531 /* NFS file lock reclaim refused */
#endif
uapi/linux/errno.h
#include <asm/errno.h>
asm/errno.h
#include <asm-generic/errno.h>
asm-generic/errno.h
#include <asm-generic/errno-base.h>
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
/*
* This error code is special: arch syscall entry code will return
* -ENOSYS if users try to call a syscall that doesn't exist. To keep
* failures of syscalls that really do exist distinguishable from
* failures due to attempts to use a nonexistent syscall, syscall
* implementations should refrain from returning -ENOSYS.
*/
#define ENOSYS 38 /* Invalid system call number */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ECANCELED 125 /* Operation Canceled */
#define ENOKEY 126 /* Required key not available */
#define EKEYEXPIRED 127 /* Key has expired */
#define EKEYREVOKED 128 /* Key has been revoked */
#define EKEYREJECTED 129 /* Key was rejected by service */
/* for robust mutexes */
#define EOWNERDEAD 130 /* Owner died */
#define ENOTRECOVERABLE 131 /* State not recoverable */
#define ERFKILL 132 /* Operation not possible due to RF-kill */
#define EHWPOISON 133 /* Memory page has hardware error */
#endif
errno-base.h
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _ASM_GENERIC_ERRNO_BASE_H
#define _ASM_GENERIC_ERRNO_BASE_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 */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#endif
2, Windows系统
errno 常量是针对各种错误条件分配给 errno 的值。
The errno constants are values assigned to errno for various error conditions.
ERRNO.H包含errno值的定义。不过,并非所有在ERRNO.H 中给出的定义都用于 32 位 Windows 操作系统。ERRNO.H中的某些值是为了保持与UNIX系列操作系统的兼容性。32 位 Windows 操作系统中的 errno 值是 UNIX 系统中 errno 值的子集。
ERRNO.H contains the definitions of the errno values. However, not all the definitions given in ERRNO.H are used in 32-bit Windows operating systems. Some of the values in ERRNO.H are present to maintain compatibility with the UNIX family of operating systems. The errno values in a 32-bit Windows operating system are a subset of the values for errno in UNIX systems.
errno 值不一定与 Windows 操作系统的系统调用返回的实际错误代码相同。要访问实际的操作系统错误代码,请使用包含该值的 _doserrno 变量。
The errno value isn't necessarily the same as the actual error code returned by a system call from the Windows operating system. To access the actual operating system error code, use the _doserrno variable, which contains this value.
The following errno values are supported:
Constant
|
Description
|
Value
|
E2BIG
|
Argument list too long.
|
7
|
EACCES
|
Permission denied. The file's permission setting does not allow the specified access. This error signifies that an attempt was made to access a file (or, in some cases, a directory) in a way that is incompatible with the file's attributes.
For example, the error can occur when an attempt is made to read from a file that is not open, to open an existing read-only file for writing, or to open a directory instead of a file. Under MS-DOS operating system versions 3.0 and later, EACCES may also indicate a locking or sharing violation.
The error can also occur in an attempt to rename a file or directory or to remove an existing directory.
|
13
|
EAGAIN
|
No more processes or not enough memory or maximum nesting level reached. An attempt to create a new process failed because there are no more process slots, or there is not enough memory, or the maximum nesting level has been reached.
|
11
|
EBADF
|
Bad file number. There are two possible causes: 1) The specified file descriptor is not a valid value or does not refer to an open file. 2) An attempt was made to write to a file or device opened for read-only access.
|
9
|
EBUSY
|
Device or resource busy.
|
16
|
ECHILD
|
No spawned processes.
|
10
|
EDEADLK
|
Resource deadlock would occur.
|
36
|
EDEADLOCK
|
Same as EDEADLK for compatibility with older Microsoft C versions.
|
36
|
EDOM
|
Math argument. The argument to a math function is not in the domain of the function.
|
33
|
EEXIST
|
Files exists. An attempt has been made to create a file that already exists. For example, the _O_CREAT and _O_EXCL flags are specified in an _open call, but the named file already exists.
|
17
|
EFAULT
|
Bad address.
|
14
|
EFBIG
|
File too large.
|
27
|
EILSEQ
|
Illegal sequence of bytes (for example, in an MBCS string).
|
42
|
EINTR
|
Interrupted function.
|
4
|
EINVAL
|
Invalid argument. An invalid value was given for one of the arguments to a function. For example, the value given for the origin when positioning a file pointer (by means of a call to fseek) is before the beginning of the file.
|
22
|
EIO
|
I/O error.
|
5
|
EISDIR
|
Is a directory.
|
21
|
EMFILE
|
Too many open files. No more file descriptors are available, so no more files can be opened.
|
24
|
EMLINK
|
Too many links.
|
31
|
ENAMETOOLONG
|
Filename too long.
|
38
|
ENFILE
|
Too many files open in system.
|
23
|
ENODEV
|
No such device.
|
19
|
ENOENT
|
No such file or directory. The specified file or directory does not exist or cannot be found. This message can occur whenever a specified file does not exist or a component of a path does not specify an existing directory.
|
2
|
ENOEXEC
|
Exec format error. An attempt was made to execute a file that is not executable or that has an invalid executable-file format.
|
8
|
ENOLCK
|
No locks available.
|
39
|
ENOMEM
|
Not enough memory is available for the attempted operator. For example, this message can occur when insufficient memory is available to execute a child process, or when the allocation request in a _getcwd call cannot be satisfied.
|
12
|
ENOSPC
|
No space left on device. No more space for writing is available on the device (for example, when the disk is full).
|
28
|
ENOSYS
|
Function not supported.
|
40
|
ENOTDIR
|
Not a directory.
|
20
|
ENOTEMPTY
|
Directory not empty.
|
41
|
ENOTTY
|
Inappropriate I/O control operation.
|
25
|
ENXIO
|
No such device or address.
|
6
|
EPERM
|
Operation not permitted.
|
1
|
EPIPE
|
Broken pipe.
|
32
|
ERANGE
|
Result too large. An argument to a math function is too large, resulting in partial or total loss of significance in the result. This error can also occur in other functions when an argument is larger than expected (for example, when the buffer argument to _getcwd is longer than expected).
|
34
|
EROFS
|
Read only file system.
|
30
|
ESPIPE
|
Invalid seek.
|
29
|
ESRCH
|
No such process.
|
3
|
EXDEV
|
Cross-device link. An attempt was made to move a file to a different device (using the rename function).
|
18
|
STRUNCATE
|
A string copy or concatenation resulted in a truncated string.
|
80
|
The following values are supported for compatibility with POSIX:
Constant
|
Description
|
Value
|
EADDRINUSE
|
Address in use.
|
100
|
EADDRNOTAVAIL
|
Address not available.
|
101
|
EAFNOSUPPORT
|
Address family not supported.
|
102
|
EALREADY
|
Connection already in progress.
|
103
|
EBADMSG
|
Bad message.
|
104
|
ECANCELED
|
Operation canceled.
|
105
|
ECONNABORTED
|
Connection aborted.
|
106
|
ECONNREFUSED
|
Connection refused.
|
107
|
ECONNRESET
|
Connection reset.
|
108
|
EDESTADDRREQ
|
Destination address required.
|
109
|
EHOSTUNREACH
|
Host unreachable.
|
110
|
EIDRM
|
Identifier removed.
|
111
|
EINPROGRESS
|
Operation in progress.
|
112
|
EISCONN
|
Already connected.
|
113
|
ELOOP
|
Too many symbolic link levels.
|
114
|
EMSGSIZE
|
Message size.
|
115
|
ENETDOWN
|
Network down.
|
116
|
ENETRESET
|
Network reset.
|
117
|
ENETUNREACH
|
Network unreachable.
|
118
|
ENOBUFS
|
No buffer space.
|
119
|
ENODATA
|
No message available.
|
120
|
ENOLINK
|
No link.
|
121
|
ENOMSG
|
No message.
|
122
|
ENOPROTOOPT
|
No protocol option.
|
123
|
ENOSR
|
No stream resources.
|
124
|
ENOSTR
|
Not a stream.
|
125
|
ENOTCONN
|
Not connected.
|
126
|
ENOTRECOVERABLE
|
State not recoverable.
|
127
|
ENOTSOCK
|
Not a socket.
|
128
|
ENOTSUP
|
Not supported.
|
129
|
EOPNOTSUPP
|
Operation not supported.
|
130
|
EOTHER
|
Other.
|
131
|
EOVERFLOW
|
Value too large.
|
132
|
EOWNERDEAD
|
Owner dead.
|
133
|
EPROTO
|
Protocol error.
|
134
|
EPROTONOSUPPORT
|
Protocol not supported.
|
135
|
EPROTOTYPE
|
Wrong protocol type.
|
136
|
ETIME
|
Stream timeout.
|
137
|
ETIMEDOUT
|
Timed out.
|
138
|
ETXTBSY
|
Text file busy.
|
139
|
EWOULDBLOCK
|
Operation would block.
|
140
|