]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/errno.3
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man3 / errno.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl)
2.\"
e4a74ca8 3.\" SPDX-License-Identifier: GPL-2.0-or-later
fea681da 4.\"
c11b1abf 5.\" 5 Oct 2002, Modified by Michael Kerrisk <mtk.manpages@gmail.com>
68e1685c 6.\" Updated for POSIX.1 2001
05432883
MK
7.\" 2004-12-17 Martin Schulze <joey@infodrom.org>, mtk
8.\" Removed errno declaration prototype, added notes
a0ddea87
MK
9.\" 2006-02-09 Kurt Wall, mtk
10.\" Added non-POSIX errors
fea681da 11.\"
4c1c5274 12.TH errno 3 (date) "Linux man-pages (unreleased)"
fea681da
MK
13.SH NAME
14errno \- number of last error
afa8db94
AC
15.SH LIBRARY
16Standard C library
17.RI ( libc ", " \-lc )
fea681da 18.SH SYNOPSIS
c7db92b9 19.nf
fea681da 20.B #include <errno.h>
68e4db0a 21.\".PP
05432883 22.\".BI "extern int " errno ;
c7db92b9 23.fi
fea681da 24.SH DESCRIPTION
c13182ef 25The
05432883
MK
26.I <errno.h>
27header file defines the integer variable
09b235db 28.IR errno ,
05432883
MK
29which is set by system calls and some library functions in the event
30of an error to indicate what went wrong.
b89ec852
MK
31.\"
32.SS errno
a9641f84
MK
33The value in
34.I errno
35is significant only when the return value of
929ccaa3
MK
36the call indicated an error
37(i.e., \-1 from most system calls;
38\-1 or NULL from most library functions);
39a function that succeeds
40.I is
41allowed to change
09b235db 42.IR errno .
b89ec852
MK
43The value of
44.I errno
45is never set to zero by any system call or library function.
847e0d88 46.PP
929ccaa3
MK
47For some system calls and library functions (e.g.,
48.BR getpriority (2)),
49\-1 is a valid return on success.
50In such cases, a successful return can be distinguished from an error
51return by setting
09b235db 52.I errno
929ccaa3
MK
53to zero before the call, and then,
54if the call returns a status that indicates that an error
55may have occurred, checking to see if
56.I errno
c7094399 57has a nonzero value.
847e0d88 58.PP
c6fa0841
MK
59.I errno
60is defined by the ISO C standard to be a modifiable lvalue
61of type
62.IR int ,
63and must not be explicitly declared;
64.I errno
be7fff26 65may be a macro.
c6fa0841
MK
66.I errno
67is thread-local; setting it in one thread
fea681da 68does not affect its value in any other thread.
b89ec852
MK
69.\"
70.SS Error numbers and names
9d1a5fa6 71Valid error numbers are all positive numbers.
b89ec852
MK
72The
73.I <errno.h>
74header file defines symbolic names for each
75of the possible error numbers that may appear in
76.IR errno .
847e0d88 77.PP
c13182ef 78All the error names specified by POSIX.1
05432883
MK
79must have distinct values, with the exception of
80.B EAGAIN
c13182ef 81and
05432883 82.BR EWOULDBLOCK ,
07b973b2
MK
83which may be the same.
84On Linux, these two have the same value on all architectures.
847e0d88 85.PP
f7921478
MK
86The error numbers that correspond to each symbolic name
87vary across UNIX systems,
88and even across different architectures on Linux.
b01ecc5e 89Therefore, numeric values are not included as part of the list of
bf3683a1 90error names below.
5a99c722
MK
91The
92.BR perror (3)
93and
94.BR strerror (3)
95functions can be used to convert these names to
96corresponding textual error messages.
afde18c0
MK
97.PP
98On any particular Linux system,
44a35dc8
MK
99one can obtain a list of all symbolic error names and
100the corresponding error numbers using the
101.BR errno (1)
385a5b3d
MK
102command (part of the
103.I moreutils
104package):
44a35dc8
MK
105.PP
106.in +4n
107.EX
108$ \fBerrno \-l\fP
109EPERM 1 Operation not permitted
110ENOENT 2 No such file or directory
111ESRCH 3 No such process
112EINTR 4 Interrupted system call
113EIO 5 Input/output error
114\&...
115.EE
116.in
117.PP
118The
119.BR errno (1)
d2cd4588
MK
120command can also be used to look up individual error numbers and names,
121and to search for errors using strings from the error description,
44a35dc8
MK
122as in the following examples:
123.PP
124.in +4n
125.EX
126$ \fBerrno 2\fP
127ENOENT 2 No such file or directory
128$ \fBerrno ESRCH\fP
129ESRCH 3 No such process
d2cd4588
MK
130$ \fBerrno \-s permission\fP
131EACCES 13 Permission denied
44a35dc8
MK
132.EE
133.in
7f740303 134.\".PP
a0ddea87 135.\" POSIX.1 (2001 edition) lists the following symbolic error names. Of
a8d55537
MK
136.\" these, \fBEDOM\fP and \fBERANGE\fP are in the ISO C standard. ISO C
137.\" Amendment 1 defines the additional error number \fBEILSEQ\fP for
a0ddea87 138.\" coding errors in multibyte or wide characters.
c13182ef 139.\"
b89ec852 140.SS List of error names
e4a5b662
MK
141In the list of the symbolic error names below,
142various names are marked as follows:
4279e42d
AC
143.TP
144.IR POSIX.1-2001
5a63455f
MK
145The name is defined by POSIX.1-2001,
146and is defined in later POSIX.1 versions, unless otherwise indicated.
4279e42d
AC
147.TP
148.IR POSIX.1-2008
5a63455f
MK
149The name is defined in POSIX.1-2008,
150but was not present in earlier POSIX.1 standards.
4279e42d
AC
151.TP
152.IR C99
5a63455f 153The name is defined by C99.
6c525d1c 154.PP
e4a5b662 155Below is a list of the symbolic error names that are defined on Linux:
dbb8ac51 156.TP 16
0daa9e92 157.B E2BIG
5a63455f 158Argument list too long (POSIX.1-2001).
fea681da 159.TP
0daa9e92 160.B EACCES
5a63455f 161Permission denied (POSIX.1-2001).
fea681da 162.TP
0daa9e92 163.B EADDRINUSE
5a63455f 164Address already in use (POSIX.1-2001).
fea681da 165.TP
0daa9e92 166.B EADDRNOTAVAIL
5a63455f 167Address not available (POSIX.1-2001).
a0ddea87 168.\" EADV is only an error on HURD(?)
fea681da 169.TP
0daa9e92 170.B EAFNOSUPPORT
5a63455f 171Address family not supported (POSIX.1-2001).
fea681da 172.TP
0daa9e92 173.B EAGAIN
c13182ef 174Resource temporarily unavailable (may be the same value as
a0ddea87 175.BR EWOULDBLOCK )
5a63455f 176(POSIX.1-2001).
a0ddea87 177.TP
0daa9e92 178.B EALREADY
5a63455f 179Connection already in progress (POSIX.1-2001).
a0ddea87 180.TP
0daa9e92 181.B EBADE
31071798 182Invalid exchange.
a0ddea87 183.TP
0daa9e92 184.B EBADF
5a63455f 185Bad file descriptor (POSIX.1-2001).
a0ddea87 186.TP
0daa9e92 187.B EBADFD
31071798 188File descriptor in bad state.
fea681da 189.TP
0daa9e92 190.B EBADMSG
5a63455f 191Bad message (POSIX.1-2001).
fea681da 192.TP
0daa9e92 193.B EBADR
31071798 194Invalid request descriptor.
fea681da 195.TP
0daa9e92 196.B EBADRQC
31071798 197Invalid request code.
fea681da 198.TP
0daa9e92 199.B EBADSLT
31071798 200Invalid slot.
a0ddea87 201.\" EBFONT is defined but appears not to be used by kernel or glibc.
fea681da 202.TP
0daa9e92 203.B EBUSY
5a63455f 204Device or resource busy (POSIX.1-2001).
fea681da 205.TP
0daa9e92 206.B ECANCELED
5a63455f 207Operation canceled (POSIX.1-2001).
fea681da 208.TP
0daa9e92 209.B ECHILD
5a63455f 210No child processes (POSIX.1-2001).
fea681da 211.TP
a0ddea87 212.B ECHRNG
31071798 213Channel number out of range.
fea681da 214.TP
a0ddea87 215.B ECOMM
31071798 216Communication error on send.
fea681da 217.TP
0daa9e92 218.B ECONNABORTED
5a63455f 219Connection aborted (POSIX.1-2001).
a0ddea87 220.TP
0daa9e92 221.B ECONNREFUSED
5a63455f 222Connection refused (POSIX.1-2001).
a0ddea87 223.TP
0daa9e92 224.B ECONNRESET
5a63455f 225Connection reset (POSIX.1-2001).
a0ddea87 226.TP
0daa9e92 227.B EDEADLK
5a63455f 228Resource deadlock avoided (POSIX.1-2001).
a0ddea87 229.TP
0daa9e92 230.B EDEADLOCK
07b973b2 231On most architectures, a synonym for
31071798 232.BR EDEADLK .
07b973b2
MK
233On some architectures (e.g., Linux MIPS, PowerPC, SPARC),
234it is a separate error code "File locking deadlock error".
fea681da 235.TP
0daa9e92 236.B EDESTADDRREQ
5a63455f 237Destination address required (POSIX.1-2001).
a0ddea87 238.TP
0daa9e92 239.B EDOM
31071798 240Mathematics argument out of domain of function (POSIX.1, C99).
a0ddea87
MK
241.\" EDOTDOT is defined but appears to be unused
242.TP
0daa9e92 243.B EDQUOT
a0ddea87 244.\" POSIX just says "Reserved"
5a63455f 245Disk quota exceeded (POSIX.1-2001).
a0ddea87 246.TP
0daa9e92 247.B EEXIST
5a63455f 248File exists (POSIX.1-2001).
a0ddea87 249.TP
0daa9e92 250.B EFAULT
5a63455f 251Bad address (POSIX.1-2001).
a0ddea87 252.TP
0daa9e92 253.B EFBIG
5a63455f 254File too large (POSIX.1-2001).
a0ddea87 255.TP
0daa9e92 256.B EHOSTDOWN
31071798 257Host is down.
a0ddea87 258.TP
0daa9e92 259.B EHOSTUNREACH
5a63455f 260Host is unreachable (POSIX.1-2001).
a0ddea87 261.TP
975c0f87
MK
262.B EHWPOISON
263Memory page has hardware error.
264.TP
0daa9e92 265.B EIDRM
5a63455f 266Identifier removed (POSIX.1-2001).
a0ddea87 267.TP
0daa9e92 268.B EILSEQ
d411041b 269Invalid or incomplete multibyte or wide character (POSIX.1, C99).
847e0d88 270.IP
d411041b
MK
271The text shown here is the glibc error description;
272in POSIX.1, this error is described as "Illegal byte sequence".
a0ddea87 273.TP
0daa9e92 274.B EINPROGRESS
5a63455f 275Operation in progress (POSIX.1-2001).
a0ddea87 276.TP
0daa9e92 277.B EINTR
5a63455f 278Interrupted function call (POSIX.1-2001); see
0b6d88cf 279.BR signal (7).
a0ddea87 280.TP
0daa9e92 281.B EINVAL
5a63455f 282Invalid argument (POSIX.1-2001).
fea681da 283.TP
0daa9e92 284.B EIO
5a63455f 285Input/output error (POSIX.1-2001).
fea681da 286.TP
0daa9e92 287.B EISCONN
5a63455f 288Socket is connected (POSIX.1-2001).
fea681da 289.TP
0daa9e92 290.B EISDIR
5a63455f 291Is a directory (POSIX.1-2001).
fea681da 292.TP
0daa9e92 293.B EISNAM
31071798 294Is a named type file.
fea681da 295.TP
0daa9e92 296.B EKEYEXPIRED
31071798 297Key has expired.
fea681da 298.TP
0daa9e92 299.B EKEYREJECTED
31071798 300Key was rejected by service.
fea681da 301.TP
0daa9e92 302.B EKEYREVOKED
31071798 303Key has been revoked.
fea681da 304.TP
a0ddea87 305.B EL2HLT
31071798 306Level 2 halted.
fea681da 307.TP
a0ddea87 308.B EL2NSYNC
31071798 309Level 2 not synchronized.
fea681da 310.TP
a0ddea87 311.B EL3HLT
31071798 312Level 3 halted.
fea681da 313.TP
a0ddea87 314.B EL3RST
14ecabec 315Level 3 reset.
fea681da 316.TP
0daa9e92 317.B ELIBACC
31071798 318Cannot access a needed shared library.
fea681da 319.TP
0daa9e92 320.B ELIBBAD
31071798 321Accessing a corrupted shared library.
fea681da 322.TP
0daa9e92 323.B ELIBMAX
31071798 324Attempting to link in too many shared libraries.
fea681da 325.TP
0daa9e92 326.B ELIBSCN
e1f3482c 327\&.lib section in a.out corrupted
fea681da 328.TP
0daa9e92 329.B ELIBEXEC
31071798 330Cannot exec a shared library directly.
fea681da 331.TP
975c0f87
MK
332.B ELNRANGE
333.\" ELNRNG appears to be used by a few drivers
334Link number out of range.
335.TP
0daa9e92 336.B ELOOP
5a63455f 337Too many levels of symbolic links (POSIX.1-2001).
fea681da 338.TP
0daa9e92 339.B EMEDIUMTYPE
31071798 340Wrong medium type.
fea681da 341.TP
0daa9e92 342.B EMFILE
5a63455f 343Too many open files (POSIX.1-2001).
31071798 344Commonly caused by exceeding the
1ae6b2c7 345.B RLIMIT_NOFILE
0c38aa2c 346resource limit described in
31071798 347.BR getrlimit (2).
2b851e6f
MK
348Can also be caused by exceeding the limit specified in
349.IR /proc/sys/fs/nr_open .
fea681da 350.TP
0daa9e92 351.B EMLINK
5a63455f 352Too many links (POSIX.1-2001).
fea681da 353.TP
0daa9e92 354.B EMSGSIZE
5a63455f 355Message too long (POSIX.1-2001).
fea681da 356.TP
0daa9e92 357.B EMULTIHOP
a0ddea87 358.\" POSIX says "Reserved"
5a63455f 359Multihop attempted (POSIX.1-2001).
fea681da 360.TP
0daa9e92 361.B ENAMETOOLONG
5a63455f 362Filename too long (POSIX.1-2001).
a0ddea87 363.\" ENAVAIL is defined, but appears not to be used
fea681da 364.TP
0daa9e92 365.B ENETDOWN
5a63455f 366Network is down (POSIX.1-2001).
fea681da 367.TP
0daa9e92 368.B ENETRESET
5a63455f 369Connection aborted by network (POSIX.1-2001).
fea681da 370.TP
0daa9e92 371.B ENETUNREACH
5a63455f 372Network unreachable (POSIX.1-2001).
fea681da 373.TP
0daa9e92 374.B ENFILE
5a63455f 375Too many open files in system (POSIX.1-2001).
31071798 376On Linux, this is probably a result of encountering the
1ae6b2c7 377.I /proc/sys/fs/file\-max
4a5c6f9f
MK
378limit (see
379.BR proc (5)).
975c0f87
MK
380.TP
381.B ENOANO
382.\" ENOANO appears to be used by a few drivers
383No anode.
fea681da 384.TP
0daa9e92 385.B ENOBUFS
31071798 386No buffer space available (POSIX.1 (XSI STREAMS option)).
a0ddea87 387.\" ENOCSI is defined but appears to be unused.
fea681da 388.TP
0daa9e92 389.B ENODATA
a60b5d45
AC
390The named attribute does not exist,
391or the process has no access to this attribute; see
392.BR xattr (7).
393.IP
394In POSIX.1-2001 (XSI STREAMS option),
395this error was described as
396"No message is available on the STREAM head read queue".
fea681da 397.TP
0daa9e92 398.B ENODEV
5a63455f 399No such device (POSIX.1-2001).
fea681da 400.TP
0daa9e92 401.B ENOENT
5a63455f 402No such file or directory (POSIX.1-2001).
847e0d88 403.IP
9f895e62
MK
404Typically, this error results when a specified pathname does not exist,
405or one of the components in the directory prefix of a pathname does not exist,
406or the specified pathname is a dangling symbolic link.
fea681da 407.TP
0daa9e92 408.B ENOEXEC
5a63455f 409Exec format error (POSIX.1-2001).
fea681da 410.TP
0daa9e92 411.B ENOKEY
31071798 412Required key not available.
fea681da 413.TP
0daa9e92 414.B ENOLCK
5a63455f 415No locks available (POSIX.1-2001).
fea681da 416.TP
0daa9e92 417.B ENOLINK
a0ddea87 418.\" POSIX says "Reserved"
5a63455f 419Link has been severed (POSIX.1-2001).
fea681da 420.TP
0daa9e92 421.B ENOMEDIUM
31071798 422No medium found.
fea681da 423.TP
0daa9e92 424.B ENOMEM
6386c0c8 425Not enough space/cannot allocate memory (POSIX.1-2001).
fea681da 426.TP
0daa9e92 427.B ENOMSG
5a63455f 428No message of the desired type (POSIX.1-2001).
fea681da 429.TP
0daa9e92 430.B ENONET
31071798 431Machine is not on the network.
fea681da 432.TP
0daa9e92 433.B ENOPKG
31071798 434Package not installed.
fea681da 435.TP
0daa9e92 436.B ENOPROTOOPT
5a63455f 437Protocol not available (POSIX.1-2001).
fea681da 438.TP
0daa9e92 439.B ENOSPC
5a63455f 440No space left on device (POSIX.1-2001).
fea681da 441.TP
0daa9e92 442.B ENOSR
31071798 443No STREAM resources (POSIX.1 (XSI STREAMS option)).
fea681da 444.TP
0daa9e92 445.B ENOSTR
31071798 446Not a STREAM (POSIX.1 (XSI STREAMS option)).
fea681da 447.TP
0daa9e92 448.B ENOSYS
5a63455f 449Function not implemented (POSIX.1-2001).
fea681da 450.TP
0daa9e92 451.B ENOTBLK
31071798 452Block device required.
fea681da 453.TP
0daa9e92 454.B ENOTCONN
5a63455f 455The socket is not connected (POSIX.1-2001).
fea681da 456.TP
0daa9e92 457.B ENOTDIR
5a63455f 458Not a directory (POSIX.1-2001).
fea681da 459.TP
0daa9e92 460.B ENOTEMPTY
5a63455f 461Directory not empty (POSIX.1-2001).
a0ddea87 462.\" ENOTNAM is defined but appears to be unused.
fea681da 463.TP
975c0f87 464.B ENOTRECOVERABLE
5a63455f 465State not recoverable (POSIX.1-2008).
975c0f87 466.TP
0daa9e92 467.B ENOTSOCK
5a63455f 468Not a socket (POSIX.1-2001).
fea681da 469.TP
0daa9e92 470.B ENOTSUP
5a63455f 471Operation not supported (POSIX.1-2001).
fea681da 472.TP
0daa9e92 473.B ENOTTY
5a63455f 474Inappropriate I/O control operation (POSIX.1-2001).
fea681da 475.TP
0daa9e92 476.B ENOTUNIQ
31071798 477Name not unique on network.
fea681da 478.TP
0daa9e92 479.B ENXIO
5a63455f 480No such device or address (POSIX.1-2001).
fea681da 481.TP
0daa9e92 482.B EOPNOTSUPP
5a63455f 483Operation not supported on socket (POSIX.1-2001).
ba39b288 484.IP
2f0af33b
MK
485.RB ( ENOTSUP
486and
487.B EOPNOTSUPP
488have the same value on Linux, but
a0ddea87 489according to POSIX.1 these error values should be distinct.)
fea681da 490.TP
0daa9e92 491.B EOVERFLOW
5a63455f 492Value too large to be stored in data type (POSIX.1-2001).
fea681da 493.TP
975c0f87
MK
494.B EOWNERDEAD
495.\" Used at least by the user-space side of rubost mutexes
5a63455f 496Owner died (POSIX.1-2008).
975c0f87 497.TP
0daa9e92 498.B EPERM
5a63455f 499Operation not permitted (POSIX.1-2001).
fea681da 500.TP
0daa9e92 501.B EPFNOSUPPORT
31071798 502Protocol family not supported.
a0ddea87 503.TP
0daa9e92 504.B EPIPE
5a63455f 505Broken pipe (POSIX.1-2001).
a0ddea87 506.TP
0daa9e92 507.B EPROTO
5a63455f 508Protocol error (POSIX.1-2001).
a0ddea87 509.TP
0daa9e92 510.B EPROTONOSUPPORT
5a63455f 511Protocol not supported (POSIX.1-2001).
a0ddea87 512.TP
0daa9e92 513.B EPROTOTYPE
5a63455f 514Protocol wrong type for socket (POSIX.1-2001).
a0ddea87 515.TP
0daa9e92 516.B ERANGE
31071798 517Result too large (POSIX.1, C99).
a0ddea87 518.TP
0daa9e92 519.B EREMCHG
31071798 520Remote address changed.
a0ddea87 521.TP
0daa9e92 522.B EREMOTE
31071798 523Object is remote.
a0ddea87 524.TP
0daa9e92 525.B EREMOTEIO
31071798 526Remote I/O error.
a0ddea87 527.TP
0daa9e92 528.B ERESTART
31071798 529Interrupted system call should be restarted.
a0ddea87 530.TP
975c0f87
MK
531.B ERFKILL
532.\" ERFKILL appears to be used by various drivers
533Operation not possible due to RF-kill.
534.TP
0daa9e92 535.B EROFS
5a63455f 536Read-only filesystem (POSIX.1-2001).
a0ddea87 537.TP
0daa9e92 538.B ESHUTDOWN
31071798 539Cannot send after transport endpoint shutdown.
a0ddea87 540.TP
0daa9e92 541.B ESPIPE
5a63455f 542Invalid seek (POSIX.1-2001).
a0ddea87 543.TP
0daa9e92 544.B ESOCKTNOSUPPORT
31071798 545Socket type not supported.
a0ddea87 546.TP
0daa9e92 547.B ESRCH
5a63455f 548No such process (POSIX.1-2001).
a0ddea87
MK
549.\" ESRMNT is defined but appears not to be used
550.TP
0daa9e92 551.B ESTALE
5a63455f 552Stale file handle (POSIX.1-2001).
ba39b288 553.IP
31071798 554This error can occur for NFS and for other filesystems.
a0ddea87 555.TP
0daa9e92 556.B ESTRPIPE
31071798 557Streams pipe error.
a0ddea87 558.TP
0daa9e92 559.B ETIME
5db92f96
MK
560Timer expired
561(POSIX.1 (XSI STREAMS option)).
ba39b288 562.IP
c13182ef 563(POSIX.1 says "STREAM
363a3cc9 564.BR ioctl (2)
5db92f96 565timeout".)
a0ddea87 566.TP
0daa9e92 567.B ETIMEDOUT
5a63455f 568Connection timed out (POSIX.1-2001).
975c0f87
MK
569.TP
570.B ETOOMANYREFS
571.\" ETOOMANYREFS seems to be used in net/unix/af_unix.c
572Too many references: cannot splice.
a0ddea87 573.TP
0daa9e92 574.B ETXTBSY
5a63455f 575Text file busy (POSIX.1-2001).
fea681da 576.TP
0daa9e92 577.B EUCLEAN
31071798 578Structure needs cleaning.
fea681da 579.TP
0daa9e92 580.B EUNATCH
31071798 581Protocol driver not attached.
fea681da 582.TP
0daa9e92 583.B EUSERS
31071798 584Too many users.
a0ddea87 585.TP
0daa9e92 586.B EWOULDBLOCK
fea681da 587Operation would block (may be same value as
c13182ef 588.BR EAGAIN )
5a63455f 589(POSIX.1-2001).
a0ddea87 590.TP
0daa9e92 591.B EXDEV
5a63455f 592Improper link (POSIX.1-2001).
fea681da 593.TP
a0ddea87 594.B EXFULL
31071798 595Exchange full.
05432883 596.SH NOTES
fea681da 597A common mistake is to do
e646a1ba 598.PP
a6e2f128 599.in +4n
e646a1ba 600.EX
2bc2f479 601if (somecall() == \-1) {
31a6818e 602 printf("somecall() failed\en");
fea681da
MK
603 if (errno == ...) { ... }
604}
e646a1ba 605.EE
a6e2f128 606.in
e646a1ba 607.PP
fea681da
MK
608where
609.I errno
610no longer needs to have the value it had upon return from
63aa9df0 611.IR somecall ()
05432883 612(i.e., it may have been changed by the
fb186734 613.BR printf (3)).
fea681da
MK
614If the value of
615.I errno
616should be preserved across a library call, it must be saved:
e646a1ba 617.PP
a6e2f128 618.in +4n
e646a1ba 619.EX
2bc2f479 620if (somecall() == \-1) {
fea681da 621 int errsv = errno;
31a6818e 622 printf("somecall() failed\en");
fea681da
MK
623 if (errsv == ...) { ... }
624}
b8302363 625.EE
a6e2f128 626.in
05432883 627.PP
7497e9d8
MK
628Note that the POSIX threads APIs do
629.I not
630set
631.I errno
632on error.
633Instead, on failure they return an error number as the function result.
634These error numbers have the same meanings as the error numbers returned in
635.I errno
636by other APIs.
637.PP
6eb4b782
MK
638On some ancient systems,
639.I <errno.h>
640was not present or did not declare
641.IR errno ,
642so that it was necessary to declare
05432883
MK
643.I errno
644manually
c13182ef 645(i.e.,
6eb4b782 646.IR "extern int errno" ).
05432883 647.BR "Do not do this" .
6eb4b782
MK
648It long ago ceased to be necessary,
649and it will cause problems with modern versions of the C library.
47297adb 650.SH SEE ALSO
00f3b66d 651.BR errno (1), \" In the moreutils package
d7871cf9 652.BR err (3),
37b6aec3 653.BR error (3),
fea681da
MK
654.BR perror (3),
655.BR strerror (3)