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