1ERRNO(3) Linux Programmer's Manual ERRNO(3)
2
3
4
6 errno - number of last error
7
9 #include <errno.h>
10
12 The <errno.h> header file defines the integer variable errno, which is
13 set by system calls and some library functions in the event of an error
14 to indicate what went wrong. Its value is significant only when the
15 return value of the call indicated an error (i.e., -1 from most system
16 calls; -1 or NULL from most library functions); a function that suc‐
17 ceeds is allowed to change errno.
18
19 Valid error numbers are all nonzero; errno is never set to zero by any
20 system call or library function.
21
22 For some system calls and library functions (e.g., getpriority(2)), -1
23 is a valid return on success. In such cases, a successful return can
24 be distinguished from an error return by setting errno to zero before
25 the call, and then, if the call returns a status that indicates that an
26 error may have occurred, checking to see if errno has a nonzero value.
27
28 errno is defined by the ISO C standard to be a modifiable lvalue of
29 type int, and must not be explicitly declared; errno may be a macro.
30 errno is thread-local; setting it in one thread does not affect its
31 value in any other thread.
32
33 All the error names specified by POSIX.1 must have distinct values,
34 with the exception of EAGAIN and EWOULDBLOCK, which may be the same.
35
36 Below is a list of the symbolic error names that are defined on Linux.
37 Some of these are marked POSIX.1, indicating that the name is defined
38 by POSIX.1-2001, or C99, indicating that the name is defined by C99.
39
40 E2BIG Argument list too long (POSIX.1)
41
42 EACCES Permission denied (POSIX.1)
43
44 EADDRINUSE Address already in use (POSIX.1)
45
46 EADDRNOTAVAIL Address not available (POSIX.1)
47
48 EAFNOSUPPORT Address family not supported (POSIX.1)
49
50 EAGAIN Resource temporarily unavailable (may be the same value
51 as EWOULDBLOCK) (POSIX.1)
52
53 EALREADY Connection already in progress (POSIX.1)
54
55 EBADE Invalid exchange
56
57 EBADF Bad file descriptor (POSIX.1)
58
59 EBADFD File descriptor in bad state
60
61 EBADMSG Bad message (POSIX.1)
62
63 EBADR Invalid request descriptor
64
65 EBADRQC Invalid request code
66
67 EBADSLT Invalid slot
68
69 EBUSY Device or resource busy (POSIX.1)
70
71 ECANCELED Operation canceled (POSIX.1)
72
73 ECHILD No child processes (POSIX.1)
74
75 ECHRNG Channel number out of range
76
77 ECOMM Communication error on send
78
79 ECONNABORTED Connection aborted (POSIX.1)
80
81 ECONNREFUSED Connection refused (POSIX.1)
82
83 ECONNRESET Connection reset (POSIX.1)
84
85 EDEADLK Resource deadlock avoided (POSIX.1)
86
87 EDEADLOCK Synonym for EDEADLK
88
89 EDESTADDRREQ Destination address required (POSIX.1)
90
91 EDOM Mathematics argument out of domain of function
92 (POSIX.1, C99)
93
94 EDQUOT Disk quota exceeded (POSIX.1)
95
96 EEXIST File exists (POSIX.1)
97
98 EFAULT Bad address (POSIX.1)
99
100 EFBIG File too large (POSIX.1)
101
102 EHOSTDOWN Host is down
103
104 EHOSTUNREACH Host is unreachable (POSIX.1)
105
106 EIDRM Identifier removed (POSIX.1)
107
108 EILSEQ Illegal byte sequence (POSIX.1, C99)
109
110 EINPROGRESS Operation in progress (POSIX.1)
111
112 EINTR Interrupted function call (POSIX.1); see signal(7).
113
114 EINVAL Invalid argument (POSIX.1)
115
116 EIO Input/output error (POSIX.1)
117
118 EISCONN Socket is connected (POSIX.1)
119
120 EISDIR Is a directory (POSIX.1)
121
122 EISNAM Is a named type file
123
124 EKEYEXPIRED Key has expired
125
126 EKEYREJECTED Key was rejected by service
127
128 EKEYREVOKED Key has been revoked
129
130 EL2HLT Level 2 halted
131
132 EL2NSYNC Level 2 not synchronized
133
134 EL3HLT Level 3 halted
135
136 EL3RST Level 3 halted
137
138 ELIBACC Cannot access a needed shared library
139
140 ELIBBAD Accessing a corrupted shared library
141
142 ELIBMAX Attempting to link in too many shared libraries
143
144 ELIBSCN lib section in a.out corrupted
145
146 ELIBEXEC Cannot exec a shared library directly
147
148 ELOOP Too many levels of symbolic links (POSIX.1)
149
150 EMEDIUMTYPE Wrong medium type
151
152 EMFILE Too many open files (POSIX.1)
153
154 EMLINK Too many links (POSIX.1)
155
156 EMSGSIZE Message too long (POSIX.1)
157
158 EMULTIHOP Multihop attempted (POSIX.1)
159
160 ENAMETOOLONG Filename too long (POSIX.1)
161
162 ENETDOWN Network is down (POSIX.1)
163
164 ENETRESET Connection aborted by network (POSIX.1)
165
166 ENETUNREACH Network unreachable (POSIX.1)
167
168 ENFILE Too many open files in system (POSIX.1)
169
170 ENOBUFS No buffer space available (POSIX.1 (XSI STREAMS
171 option))
172
173 ENODATA No message is available on the STREAM head read queue
174 (POSIX.1)
175
176 ENODEV No such device (POSIX.1)
177
178 ENOENT No such file or directory (POSIX.1)
179
180 ENOEXEC Exec format error (POSIX.1)
181
182 ENOKEY Required key not available
183
184 ENOLCK No locks available (POSIX.1)
185
186 ENOLINK Link has been severed (POSIX.1)
187
188 ENOMEDIUM No medium found
189
190 ENOMEM Not enough space (POSIX.1)
191
192 ENOMSG No message of the desired type (POSIX.1)
193
194 ENONET Machine is not on the network
195
196 ENOPKG Package not installed
197
198 ENOPROTOOPT Protocol not available (POSIX.1)
199
200 ENOSPC No space left on device (POSIX.1)
201
202 ENOSR No STREAM resources (POSIX.1 (XSI STREAMS option))
203
204 ENOSTR Not a STREAM (POSIX.1 (XSI STREAMS option))
205
206 ENOSYS Function not implemented (POSIX.1)
207
208 ENOTBLK Block device required
209
210 ENOTCONN The socket is not connected (POSIX.1)
211
212 ENOTDIR Not a directory (POSIX.1)
213
214 ENOTEMPTY Directory not empty (POSIX.1)
215
216 ENOTSOCK Not a socket (POSIX.1)
217
218 ENOTSUP Operation not supported (POSIX.1)
219
220 ENOTTY Inappropriate I/O control operation (POSIX.1)
221
222 ENOTUNIQ Name not unique on network
223
224 ENXIO No such device or address (POSIX.1)
225
226 EOPNOTSUPP Operation not supported on socket (POSIX.1)
227
228 (ENOTSUP and EOPNOTSUPP have the same value on Linux,
229 but according to POSIX.1 these error values should be
230 distinct.)
231
232 EOVERFLOW Value too large to be stored in data type (POSIX.1)
233
234 EPERM Operation not permitted (POSIX.1)
235
236 EPFNOSUPPORT Protocol family not supported
237
238 EPIPE Broken pipe (POSIX.1)
239
240 EPROTO Protocol error (POSIX.1)
241
242 EPROTONOSUPPORT Protocol not supported (POSIX.1)
243
244 EPROTOTYPE Protocol wrong type for socket (POSIX.1)
245
246 ERANGE Result too large (POSIX.1, C99)
247
248 EREMCHG Remote address changed
249
250 EREMOTE Object is remote
251
252 EREMOTEIO Remote I/O error
253
254 ERESTART Interrupted system call should be restarted
255
256 EROFS Read-only file system (POSIX.1)
257
258 ESHUTDOWN Cannot send after transport endpoint shutdown
259
260 ESPIPE Invalid seek (POSIX.1)
261
262 ESOCKTNOSUPPORT Socket type not supported
263
264 ESRCH No such process (POSIX.1)
265
266 ESTALE Stale file handle (POSIX.1)
267
268 This error can occur for NFS and for other file systems
269
270 ESTRPIPE Streams pipe error
271
272 ETIME Timer expired (POSIX.1 (XSI STREAMS option))
273
274 (POSIX.1 says "STREAM ioctl(2) timeout")
275
276 ETIMEDOUT Connection timed out (POSIX.1)
277
278 ETXTBSY Text file busy (POSIX.1)
279
280 EUCLEAN Structure needs cleaning
281
282 EUNATCH Protocol driver not attached
283
284 EUSERS Too many users
285
286 EWOULDBLOCK Operation would block (may be same value as EAGAIN)
287 (POSIX.1)
288
289 EXDEV Improper link (POSIX.1)
290
291 EXFULL Exchange full
292
294 A common mistake is to do
295
296 if (somecall() == -1) {
297 printf("somecall() failed\n");
298 if (errno == ...) { ... }
299 }
300
301 where errno no longer needs to have the value it had upon return from
302 somecall() (i.e., it may have been changed by the printf(3)). If the
303 value of errno should be preserved across a library call, it must be
304 saved:
305
306 if (somecall() == -1) {
307 int errsv = errno;
308 printf("somecall() failed\n");
309 if (errsv == ...) { ... }
310 }
311
312 It was common in traditional C to declare errno manually (i.e., extern
313 int errno) instead of including <errno.h>. Do not do this. It will
314 not work with modern versions of the C library. However, on (very) old
315 Unix systems, there may be no <errno.h> and the declaration is needed.
316
318 err(3), error(3), perror(3), strerror(3)
319
321 This page is part of release 3.25 of the Linux man-pages project. A
322 description of the project, and information about reporting bugs, can
323 be found at http://www.kernel.org/doc/man-pages/.
324
325
326
327 2008-07-09 ERRNO(3)