]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/perror.3
proc.5: Note kernel version for /proc/PID/smaps VmFlags "wf" flag
[thirdparty/man-pages.git] / man3 / perror.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1994 Michael Haardt (michael@moria.de), 1994-06-04
2.\" Copyright (c) 1995 Michael Haardt
3.\" (michael@cantor.informatik.rwth-aachen.de), 1995-03-16
4.\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl), 1996-01-13
5.\"
1dd72f9c 6.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
7.\" This is free documentation; you can redistribute it and/or
8.\" modify it under the terms of the GNU General Public License as
9.\" published by the Free Software Foundation; either version 2 of
10.\" the License, or (at your option) any later version.
11.\"
12.\" The GNU General Public License's references to "object code"
13.\" and "executables" are to be interpreted as the output of any
14.\" document formatting or typesetting system, including
15.\" intermediate and printed output.
16.\"
17.\" This manual is distributed in the hope that it will be useful,
18.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
19.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20.\" GNU General Public License for more details.
21.\"
22.\" You should have received a copy of the GNU General Public
c715f741
MK
23.\" License along with this manual; if not, see
24.\" <http://www.gnu.org/licenses/>.
6a8d8745 25.\" %%%LICENSE_END
fea681da
MK
26.\"
27.\" 1996-01-13 aeb: merged in some text contributed by Melvin Smith
28.\" (msmith@falcon.mercer.peachnet.edu) and various other changes.
29.\" Modified 1996-05-16 by Martin Schulze (joey@infodrom.north.de)
30.\"
9ba01802 31.TH PERROR 3 2019-03-06 "" "Linux Programmer's Manual"
fea681da
MK
32.SH NAME
33perror \- print a system error message
34.SH SYNOPSIS
35.B #include <stdio.h>
68e4db0a 36.PP
01038eba 37.BI "void perror(const char *" s );
f90f031e 38
fea681da 39.B #include <errno.h>
68e4db0a 40.PP
6729be54 41.BI "const char * const " sys_errlist [];
fea681da
MK
42.br
43.BI "int " sys_nerr ;
44.br
e82a01da 45.BI "int " errno "; \fR/* Not really declared this way; see errno(3) */"
68e4db0a 46.PP
cc4615cc
MK
47.in -4n
48Feature Test Macro Requirements for glibc (see
49.BR feature_test_macros (7)):
50.in
68e4db0a 51.PP
cc4615cc
MK
52.IR sys_errlist ,
53.IR sys_nerr :
51c612fb
MK
54 Since glibc 2.19:
55 _DEFAULT_SOURCE
56 Glibc 2.19 and earlier:
57 _BSD_SOURCE
fea681da 58.SH DESCRIPTION
e82a01da 59The
63aa9df0 60.BR perror ()
e82a01da 61function produces a message on standard error describing the last
fea681da 62error encountered during a call to a system or library function.
847e0d88 63.PP
fea681da
MK
64First (if
65.I s
66is not NULL and
bd9b2a9c 67.I *s
d1a71985 68is not a null byte (\(aq\e0\(aq)), the argument string
fea681da
MK
69.I s
70is printed, followed by a colon and a blank.
e82a01da
MK
71Then an error message corresponding to the current value of
72.I errno
73and a new-line.
847e0d88 74.PP
fea681da 75To be of most use, the argument string should include the name
c13182ef 76of the function that incurred the error.
847e0d88 77.PP
fea681da 78The global error list
e82a01da
MK
79.IR sys_errlist "[],"
80which can be indexed by
81.IR errno ,
fea681da
MK
82can be used to obtain the error message without the newline.
83The largest message number provided in the table is
b29f2872 84.IR sys_nerr "\-1."
e82a01da 85Be careful when directly accessing this list, because new error values
fea681da
MK
86may not have been added to
87.IR sys_errlist "[]."
79038fa7
MK
88The use of
89.IR sys_errlist "[]"
88cc4cb6
MK
90is nowadays deprecated; use
91.BR strerror (3)
3144b412 92instead.
847e0d88 93.PP
fea681da
MK
94When a system call fails, it usually returns \-1 and sets the
95variable
96.I errno
c13182ef
MK
97to a value describing what went wrong.
98(These values can be found in
a9a13a50 99.IR <errno.h> .)
fea681da
MK
100Many library functions do likewise.
101The function
63aa9df0 102.BR perror ()
fea681da
MK
103serves to translate this error code into human-readable form.
104Note that
105.I errno
7e16fc97 106is undefined after a successful system call or library function call:
fea681da
MK
107this call may well change this variable, even though it succeeds,
108for example because it internally used some other library function that failed.
109Thus, if a failing call is not immediately followed by a call to
e511ffb6 110.BR perror (),
fea681da
MK
111the value of
112.I errno
113should be saved.
80563762
ZL
114.SH ATTRIBUTES
115For an explanation of the terms used in this section, see
116.BR attributes (7).
117.TS
118allbox;
119lb lb lb
120l l l.
121Interface Attribute Value
122T{
123.BR perror ()
124T} Thread safety MT-Safe race:stderr
125.TE
847e0d88 126.sp 1
47297adb 127.SH CONFORMING TO
780e4423
MK
128.BR perror (),
129.IR errno :
99ee5719 130POSIX.1-2001, POSIX.1-2008, C89, C99, 4.3BSD.
847e0d88 131.PP
fea681da
MK
132The externals
133.I sys_nerr
134and
135.I sys_errlist
98ed7d1d 136derive from BSD, but are not specified in POSIX.1.
19c98696 137.SH NOTES
fea681da
MK
138The externals
139.I sys_nerr
140and
141.I sys_errlist
142are defined by glibc, but in
143.IR <stdio.h> .
144.\" and only when _BSD_SOURCE is defined.
c3dfd2c8 145.\" When
cc4615cc
MK
146.\" .B _GNU_SOURCE
147.\" is defined, the symbols
fea681da
MK
148.\" .I _sys_nerr
149.\" and
150.\" .I _sys_errlist
151.\" are provided.
47297adb 152.SH SEE ALSO
d7871cf9 153.BR err (3),
fea681da 154.BR errno (3),
37b6aec3 155.BR error (3),
fea681da 156.BR strerror (3)