]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/errno.3
ttyslot.3: tfix
[thirdparty/man-pages.git] / man3 / errno.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl)
2.\"
1dd72f9c 3.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
4.\" This is free documentation; you can redistribute it and/or
5.\" modify it under the terms of the GNU General Public License as
6.\" published by the Free Software Foundation; either version 2 of
7.\" the License, or (at your option) any later version.
8.\"
9.\" The GNU General Public License's references to "object code"
10.\" and "executables" are to be interpreted as the output of any
11.\" document formatting or typesetting system, including
12.\" intermediate and printed output.
13.\"
14.\" This manual is distributed in the hope that it will be useful,
15.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.\" GNU General Public License for more details.
18.\"
19.\" You should have received a copy of the GNU General Public
c715f741
MK
20.\" License along with this manual; if not, see
21.\" <http://www.gnu.org/licenses/>.
6a8d8745 22.\" %%%LICENSE_END
fea681da 23.\"
c11b1abf 24.\" 5 Oct 2002, Modified by Michael Kerrisk <mtk.manpages@gmail.com>
68e1685c 25.\" Updated for POSIX.1 2001
05432883
MK
26.\" 2004-12-17 Martin Schulze <joey@infodrom.org>, mtk
27.\" Removed errno declaration prototype, added notes
a0ddea87
MK
28.\" 2006-02-09 Kurt Wall, mtk
29.\" Added non-POSIX errors
fea681da 30.\"
8538a62b 31.TH ERRNO 3 2018-02-02 "" "Linux Programmer's Manual"
fea681da
MK
32.SH NAME
33errno \- number of last error
34.SH SYNOPSIS
35.B #include <errno.h>
68e4db0a 36.\".PP
05432883 37.\".BI "extern int " errno ;
fea681da 38.SH DESCRIPTION
c13182ef 39The
05432883
MK
40.I <errno.h>
41header file defines the integer variable
09b235db 42.IR errno ,
05432883
MK
43which is set by system calls and some library functions in the event
44of an error to indicate what went wrong.
b89ec852
MK
45.\"
46.SS errno
a9641f84
MK
47The value in
48.I errno
49is significant only when the return value of
929ccaa3
MK
50the call indicated an error
51(i.e., \-1 from most system calls;
52\-1 or NULL from most library functions);
53a function that succeeds
54.I is
55allowed to change
09b235db 56.IR errno .
b89ec852
MK
57The value of
58.I errno
59is never set to zero by any system call or library function.
847e0d88 60.PP
929ccaa3
MK
61For some system calls and library functions (e.g.,
62.BR getpriority (2)),
63\-1 is a valid return on success.
64In such cases, a successful return can be distinguished from an error
65return by setting
09b235db 66.I errno
929ccaa3
MK
67to zero before the call, and then,
68if the call returns a status that indicates that an error
69may have occurred, checking to see if
70.I errno
c7094399 71has a nonzero value.
847e0d88 72.PP
c6fa0841
MK
73.I errno
74is defined by the ISO C standard to be a modifiable lvalue
75of type
76.IR int ,
77and must not be explicitly declared;
78.I errno
be7fff26 79may be a macro.
c6fa0841
MK
80.I errno
81is thread-local; setting it in one thread
fea681da 82does not affect its value in any other thread.
b89ec852
MK
83.\"
84.SS Error numbers and names
9d1a5fa6 85Valid error numbers are all positive numbers.
b89ec852
MK
86The
87.I <errno.h>
88header file defines symbolic names for each
89of the possible error numbers that may appear in
90.IR errno .
847e0d88 91.PP
c13182ef 92All the error names specified by POSIX.1
05432883
MK
93must have distinct values, with the exception of
94.B EAGAIN
c13182ef 95and
05432883
MK
96.BR EWOULDBLOCK ,
97which may be the same.
847e0d88 98.PP
f7921478
MK
99The error numbers that correspond to each symbolic name
100vary across UNIX systems,
101and even across different architectures on Linux.
b01ecc5e 102Therefore, numeric values are not included as part of the list of
bf3683a1 103error names below.
5a99c722
MK
104The
105.BR perror (3)
106and
107.BR strerror (3)
108functions can be used to convert these names to
109corresponding textual error messages.
afde18c0
MK
110.PP
111On any particular Linux system,
44a35dc8
MK
112one can obtain a list of all symbolic error names and
113the corresponding error numbers using the
114.BR errno (1)
115command:
116.PP
117.in +4n
118.EX
119$ \fBerrno \-l\fP
120EPERM 1 Operation not permitted
121ENOENT 2 No such file or directory
122ESRCH 3 No such process
123EINTR 4 Interrupted system call
124EIO 5 Input/output error
125\&...
126.EE
127.in
128.PP
129The
130.BR errno (1)
d2cd4588
MK
131command can also be used to look up individual error numbers and names,
132and to search for errors using strings from the error description,
44a35dc8
MK
133as in the following examples:
134.PP
135.in +4n
136.EX
137$ \fBerrno 2\fP
138ENOENT 2 No such file or directory
139$ \fBerrno ESRCH\fP
140ESRCH 3 No such process
d2cd4588
MK
141$ \fBerrno \-s permission\fP
142EACCES 13 Permission denied
44a35dc8
MK
143.EE
144.in
bf3683a1 145.PP
a0ddea87 146.\" POSIX.1 (2001 edition) lists the following symbolic error names. Of
a8d55537
MK
147.\" these, \fBEDOM\fP and \fBERANGE\fP are in the ISO C standard. ISO C
148.\" Amendment 1 defines the additional error number \fBEILSEQ\fP for
a0ddea87 149.\" coding errors in multibyte or wide characters.
c13182ef 150.\"
b89ec852 151.SS List of error names
e4a5b662
MK
152In the list of the symbolic error names below,
153various names are marked as follows:
5a63455f
MK
154.IP * 3
155.IR POSIX.1-2001 :
156The name is defined by POSIX.1-2001,
157and is defined in later POSIX.1 versions, unless otherwise indicated.
158.IP *
159.IR POSIX.1-2008 :
160The name is defined in POSIX.1-2008,
161but was not present in earlier POSIX.1 standards.
162.IP *
163.IR C99 :
164The name is defined by C99.
e4a5b662 165Below is a list of the symbolic error names that are defined on Linux:
dbb8ac51 166.TP 16
0daa9e92 167.B E2BIG
5a63455f 168Argument list too long (POSIX.1-2001).
fea681da 169.TP
0daa9e92 170.B EACCES
5a63455f 171Permission denied (POSIX.1-2001).
fea681da 172.TP
0daa9e92 173.B EADDRINUSE
5a63455f 174Address already in use (POSIX.1-2001).
fea681da 175.TP
0daa9e92 176.B EADDRNOTAVAIL
5a63455f 177Address not available (POSIX.1-2001).
a0ddea87 178.\" EADV is only an error on HURD(?)
fea681da 179.TP
0daa9e92 180.B EAFNOSUPPORT
5a63455f 181Address family not supported (POSIX.1-2001).
fea681da 182.TP
0daa9e92 183.B EAGAIN
c13182ef 184Resource temporarily unavailable (may be the same value as
a0ddea87 185.BR EWOULDBLOCK )
5a63455f 186(POSIX.1-2001).
a0ddea87 187.TP
0daa9e92 188.B EALREADY
5a63455f 189Connection already in progress (POSIX.1-2001).
a0ddea87 190.TP
0daa9e92 191.B EBADE
31071798 192Invalid exchange.
a0ddea87 193.TP
0daa9e92 194.B EBADF
5a63455f 195Bad file descriptor (POSIX.1-2001).
a0ddea87 196.TP
0daa9e92 197.B EBADFD
31071798 198File descriptor in bad state.
fea681da 199.TP
0daa9e92 200.B EBADMSG
5a63455f 201Bad message (POSIX.1-2001).
fea681da 202.TP
0daa9e92 203.B EBADR
31071798 204Invalid request descriptor.
fea681da 205.TP
0daa9e92 206.B EBADRQC
31071798 207Invalid request code.
fea681da 208.TP
0daa9e92 209.B EBADSLT
31071798 210Invalid slot.
a0ddea87 211.\" EBFONT is defined but appears not to be used by kernel or glibc.
fea681da 212.TP
0daa9e92 213.B EBUSY
5a63455f 214Device or resource busy (POSIX.1-2001).
fea681da 215.TP
0daa9e92 216.B ECANCELED
5a63455f 217Operation canceled (POSIX.1-2001).
fea681da 218.TP
0daa9e92 219.B ECHILD
5a63455f 220No child processes (POSIX.1-2001).
fea681da 221.TP
a0ddea87 222.B ECHRNG
31071798 223Channel number out of range.
fea681da 224.TP
a0ddea87 225.B ECOMM
31071798 226Communication error on send.
fea681da 227.TP
0daa9e92 228.B ECONNABORTED
5a63455f 229Connection aborted (POSIX.1-2001).
a0ddea87 230.TP
0daa9e92 231.B ECONNREFUSED
5a63455f 232Connection refused (POSIX.1-2001).
a0ddea87 233.TP
0daa9e92 234.B ECONNRESET
5a63455f 235Connection reset (POSIX.1-2001).
a0ddea87 236.TP
0daa9e92 237.B EDEADLK
5a63455f 238Resource deadlock avoided (POSIX.1-2001).
a0ddea87 239.TP
0daa9e92 240.B EDEADLOCK
a0ddea87 241Synonym for
31071798 242.BR EDEADLK .
fea681da 243.TP
0daa9e92 244.B EDESTADDRREQ
5a63455f 245Destination address required (POSIX.1-2001).
a0ddea87 246.TP
0daa9e92 247.B EDOM
31071798 248Mathematics argument out of domain of function (POSIX.1, C99).
a0ddea87
MK
249.\" EDOTDOT is defined but appears to be unused
250.TP
0daa9e92 251.B EDQUOT
a0ddea87 252.\" POSIX just says "Reserved"
5a63455f 253Disk quota exceeded (POSIX.1-2001).
a0ddea87 254.TP
0daa9e92 255.B EEXIST
5a63455f 256File exists (POSIX.1-2001).
a0ddea87 257.TP
0daa9e92 258.B EFAULT
5a63455f 259Bad address (POSIX.1-2001).
a0ddea87 260.TP
0daa9e92 261.B EFBIG
5a63455f 262File too large (POSIX.1-2001).
a0ddea87 263.TP
0daa9e92 264.B EHOSTDOWN
31071798 265Host is down.
a0ddea87 266.TP
0daa9e92 267.B EHOSTUNREACH
5a63455f 268Host is unreachable (POSIX.1-2001).
a0ddea87 269.TP
975c0f87
MK
270.B EHWPOISON
271Memory page has hardware error.
272.TP
0daa9e92 273.B EIDRM
5a63455f 274Identifier removed (POSIX.1-2001).
a0ddea87 275.TP
0daa9e92 276.B EILSEQ
d411041b 277Invalid or incomplete multibyte or wide character (POSIX.1, C99).
847e0d88 278.IP
d411041b
MK
279The text shown here is the glibc error description;
280in POSIX.1, this error is described as "Illegal byte sequence".
a0ddea87 281.TP
0daa9e92 282.B EINPROGRESS
5a63455f 283Operation in progress (POSIX.1-2001).
a0ddea87 284.TP
0daa9e92 285.B EINTR
5a63455f 286Interrupted function call (POSIX.1-2001); see
0b6d88cf 287.BR signal (7).
a0ddea87 288.TP
0daa9e92 289.B EINVAL
5a63455f 290Invalid argument (POSIX.1-2001).
fea681da 291.TP
0daa9e92 292.B EIO
5a63455f 293Input/output error (POSIX.1-2001).
fea681da 294.TP
0daa9e92 295.B EISCONN
5a63455f 296Socket is connected (POSIX.1-2001).
fea681da 297.TP
0daa9e92 298.B EISDIR
5a63455f 299Is a directory (POSIX.1-2001).
fea681da 300.TP
0daa9e92 301.B EISNAM
31071798 302Is a named type file.
fea681da 303.TP
0daa9e92 304.B EKEYEXPIRED
31071798 305Key has expired.
fea681da 306.TP
0daa9e92 307.B EKEYREJECTED
31071798 308Key was rejected by service.
fea681da 309.TP
0daa9e92 310.B EKEYREVOKED
31071798 311Key has been revoked.
fea681da 312.TP
a0ddea87 313.B EL2HLT
31071798 314Level 2 halted.
fea681da 315.TP
a0ddea87 316.B EL2NSYNC
31071798 317Level 2 not synchronized.
fea681da 318.TP
a0ddea87 319.B EL3HLT
31071798 320Level 3 halted.
fea681da 321.TP
a0ddea87 322.B EL3RST
14ecabec 323Level 3 reset.
fea681da 324.TP
0daa9e92 325.B ELIBACC
31071798 326Cannot access a needed shared library.
fea681da 327.TP
0daa9e92 328.B ELIBBAD
31071798 329Accessing a corrupted shared library.
fea681da 330.TP
0daa9e92 331.B ELIBMAX
31071798 332Attempting to link in too many shared libraries.
fea681da 333.TP
0daa9e92 334.B ELIBSCN
e1f3482c 335\&.lib section in a.out corrupted
fea681da 336.TP
0daa9e92 337.B ELIBEXEC
31071798 338Cannot exec a shared library directly.
fea681da 339.TP
975c0f87
MK
340.B ELNRANGE
341.\" ELNRNG appears to be used by a few drivers
342Link number out of range.
343.TP
0daa9e92 344.B ELOOP
5a63455f 345Too many levels of symbolic links (POSIX.1-2001).
fea681da 346.TP
0daa9e92 347.B EMEDIUMTYPE
31071798 348Wrong medium type.
fea681da 349.TP
0daa9e92 350.B EMFILE
5a63455f 351Too many open files (POSIX.1-2001).
31071798 352Commonly caused by exceeding the
0c38aa2c
MK
353.BR RLIMIT_NOFILE
354resource limit described in
31071798 355.BR getrlimit (2).
fea681da 356.TP
0daa9e92 357.B EMLINK
5a63455f 358Too many links (POSIX.1-2001).
fea681da 359.TP
0daa9e92 360.B EMSGSIZE
5a63455f 361Message too long (POSIX.1-2001).
fea681da 362.TP
0daa9e92 363.B EMULTIHOP
a0ddea87 364.\" POSIX says "Reserved"
5a63455f 365Multihop attempted (POSIX.1-2001).
fea681da 366.TP
0daa9e92 367.B ENAMETOOLONG
5a63455f 368Filename too long (POSIX.1-2001).
a0ddea87 369.\" ENAVAIL is defined, but appears not to be used
fea681da 370.TP
0daa9e92 371.B ENETDOWN
5a63455f 372Network is down (POSIX.1-2001).
fea681da 373.TP
0daa9e92 374.B ENETRESET
5a63455f 375Connection aborted by network (POSIX.1-2001).
fea681da 376.TP
0daa9e92 377.B ENETUNREACH
5a63455f 378Network unreachable (POSIX.1-2001).
fea681da 379.TP
0daa9e92 380.B ENFILE
5a63455f 381Too many open files in system (POSIX.1-2001).
31071798 382On Linux, this is probably a result of encountering the
4a5c6f9f
MK
383.IR /proc/sys/fs/file-max
384limit (see
385.BR proc (5)).
975c0f87
MK
386.TP
387.B ENOANO
388.\" ENOANO appears to be used by a few drivers
389No anode.
fea681da 390.TP
0daa9e92 391.B ENOBUFS
31071798 392No buffer space available (POSIX.1 (XSI STREAMS option)).
a0ddea87 393.\" ENOCSI is defined but appears to be unused.
fea681da 394.TP
0daa9e92 395.B ENODATA
5a63455f 396No message is available on the STREAM head read queue (POSIX.1-2001).
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
6eb4b782
MK
628On some ancient systems,
629.I <errno.h>
630was not present or did not declare
631.IR errno ,
632so that it was necessary to declare
05432883
MK
633.I errno
634manually
c13182ef 635(i.e.,
6eb4b782 636.IR "extern int errno" ).
05432883 637.BR "Do not do this" .
6eb4b782
MK
638It long ago ceased to be necessary,
639and it will cause problems with modern versions of the C library.
47297adb 640.SH SEE ALSO
00f3b66d 641.BR errno (1), \" In the moreutils package
d7871cf9 642.BR err (3),
37b6aec3 643.BR error (3),
fea681da
MK
644.BR perror (3),
645.BR strerror (3)