]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/perror.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / perror.3
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 .\"
6 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
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
23 .\" License along with this manual; if not, see
24 .\" <http://www.gnu.org/licenses/>.
25 .\" %%%LICENSE_END
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 .\"
31 .TH PERROR 3 2019-03-06 "" "Linux Programmer's Manual"
32 .SH NAME
33 perror \- print a system error message
34 .SH SYNOPSIS
35 .B #include <stdio.h>
36 .PP
37 .BI "void perror(const char *" s );
38
39 .B #include <errno.h>
40 .PP
41 .BI "const char * const " sys_errlist [];
42 .br
43 .BI "int " sys_nerr ;
44 .br
45 .BI "int " errno "; \fR/* Not really declared this way; see errno(3) */"
46 .PP
47 .in -4n
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
50 .in
51 .PP
52 .IR sys_errlist ,
53 .IR sys_nerr :
54 Since glibc 2.19:
55 _DEFAULT_SOURCE
56 Glibc 2.19 and earlier:
57 _BSD_SOURCE
58 .SH DESCRIPTION
59 The
60 .BR perror ()
61 function produces a message on standard error describing the last
62 error encountered during a call to a system or library function.
63 .PP
64 First (if
65 .I s
66 is not NULL and
67 .I *s
68 is not a null byte (\(aq\e0\(aq)), the argument string
69 .I s
70 is printed, followed by a colon and a blank.
71 Then an error message corresponding to the current value of
72 .I errno
73 and a new-line.
74 .PP
75 To be of most use, the argument string should include the name
76 of the function that incurred the error.
77 .PP
78 The global error list
79 .IR sys_errlist "[],"
80 which can be indexed by
81 .IR errno ,
82 can be used to obtain the error message without the newline.
83 The largest message number provided in the table is
84 .IR sys_nerr "\-1."
85 Be careful when directly accessing this list, because new error values
86 may not have been added to
87 .IR sys_errlist "[]."
88 The use of
89 .IR sys_errlist "[]"
90 is nowadays deprecated; use
91 .BR strerror (3)
92 instead.
93 .PP
94 When a system call fails, it usually returns \-1 and sets the
95 variable
96 .I errno
97 to a value describing what went wrong.
98 (These values can be found in
99 .IR <errno.h> .)
100 Many library functions do likewise.
101 The function
102 .BR perror ()
103 serves to translate this error code into human-readable form.
104 Note that
105 .I errno
106 is undefined after a successful system call or library function call:
107 this call may well change this variable, even though it succeeds,
108 for example because it internally used some other library function that failed.
109 Thus, if a failing call is not immediately followed by a call to
110 .BR perror (),
111 the value of
112 .I errno
113 should be saved.
114 .SH ATTRIBUTES
115 For an explanation of the terms used in this section, see
116 .BR attributes (7).
117 .TS
118 allbox;
119 lb lb lb
120 l l l.
121 Interface Attribute Value
122 T{
123 .BR perror ()
124 T} Thread safety MT-Safe race:stderr
125 .TE
126 .sp 1
127 .SH CONFORMING TO
128 .BR perror (),
129 .IR errno :
130 POSIX.1-2001, POSIX.1-2008, C89, C99, 4.3BSD.
131 .PP
132 The externals
133 .I sys_nerr
134 and
135 .I sys_errlist
136 derive from BSD, but are not specified in POSIX.1.
137 .SH NOTES
138 The externals
139 .I sys_nerr
140 and
141 .I sys_errlist
142 are defined by glibc, but in
143 .IR <stdio.h> .
144 .\" and only when _BSD_SOURCE is defined.
145 .\" When
146 .\" .B _GNU_SOURCE
147 .\" is defined, the symbols
148 .\" .I _sys_nerr
149 .\" and
150 .\" .I _sys_errlist
151 .\" are provided.
152 .SH SEE ALSO
153 .BR err (3),
154 .BR errno (3),
155 .BR error (3),
156 .BR strerror (3)