]>
Commit | Line | Data |
---|---|---|
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 | .\" | |
5722c835 | 31 | .TH PERROR 3 2015-07-23 "" "Linux Programmer's Manual" |
fea681da MK |
32 | .SH NAME |
33 | perror \- print a system error message | |
34 | .SH SYNOPSIS | |
35 | .B #include <stdio.h> | |
36 | .sp | |
01038eba | 37 | .BI "void perror(const char *" s ); |
fea681da MK |
38 | .sp |
39 | .B #include <errno.h> | |
40 | .sp | |
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) */" |
cc4615cc MK |
46 | .sp |
47 | .in -4n | |
48 | Feature Test Macro Requirements for glibc (see | |
49 | .BR feature_test_macros (7)): | |
50 | .in | |
51 | .sp | |
52 | .IR sys_errlist , | |
53 | .IR sys_nerr : | |
54 | _BSD_SOURCE | |
fea681da | 55 | .SH DESCRIPTION |
e82a01da | 56 | The |
63aa9df0 | 57 | .BR perror () |
e82a01da | 58 | function produces a message on standard error describing the last |
fea681da | 59 | error encountered during a call to a system or library function. |
e82a01da | 60 | |
fea681da MK |
61 | First (if |
62 | .I s | |
63 | is not NULL and | |
bd9b2a9c | 64 | .I *s |
e82a01da | 65 | is not a null byte (\(aq\\0\(aq)), the argument string |
fea681da MK |
66 | .I s |
67 | is printed, followed by a colon and a blank. | |
e82a01da MK |
68 | Then an error message corresponding to the current value of |
69 | .I errno | |
70 | and a new-line. | |
fea681da MK |
71 | |
72 | To be of most use, the argument string should include the name | |
c13182ef | 73 | of the function that incurred the error. |
fea681da MK |
74 | |
75 | The global error list | |
e82a01da MK |
76 | .IR sys_errlist "[]," |
77 | which can be indexed by | |
78 | .IR errno , | |
fea681da MK |
79 | can be used to obtain the error message without the newline. |
80 | The largest message number provided in the table is | |
b29f2872 | 81 | .IR sys_nerr "\-1." |
e82a01da | 82 | Be careful when directly accessing this list, because new error values |
fea681da MK |
83 | may not have been added to |
84 | .IR sys_errlist "[]." | |
79038fa7 MK |
85 | The use of |
86 | .IR sys_errlist "[]" | |
87 | is nowadays deprecated. | |
88 | ||
fea681da MK |
89 | When a system call fails, it usually returns \-1 and sets the |
90 | variable | |
91 | .I errno | |
c13182ef MK |
92 | to a value describing what went wrong. |
93 | (These values can be found in | |
a9a13a50 | 94 | .IR <errno.h> .) |
fea681da MK |
95 | Many library functions do likewise. |
96 | The function | |
63aa9df0 | 97 | .BR perror () |
fea681da MK |
98 | serves to translate this error code into human-readable form. |
99 | Note that | |
100 | .I errno | |
e82a01da | 101 | is undefined after a successful sysme call or library function call: |
fea681da MK |
102 | this call may well change this variable, even though it succeeds, |
103 | for example because it internally used some other library function that failed. | |
104 | Thus, if a failing call is not immediately followed by a call to | |
e511ffb6 | 105 | .BR perror (), |
fea681da MK |
106 | the value of |
107 | .I errno | |
108 | should be saved. | |
80563762 ZL |
109 | .SH ATTRIBUTES |
110 | For an explanation of the terms used in this section, see | |
111 | .BR attributes (7). | |
112 | .TS | |
113 | allbox; | |
114 | lb lb lb | |
115 | l l l. | |
116 | Interface Attribute Value | |
117 | T{ | |
118 | .BR perror () | |
119 | T} Thread safety MT-Safe race:stderr | |
120 | .TE | |
121 | ||
47297adb | 122 | .SH CONFORMING TO |
780e4423 MK |
123 | .BR perror (), |
124 | .IR errno : | |
99ee5719 | 125 | POSIX.1-2001, POSIX.1-2008, C89, C99, 4.3BSD. |
780e4423 | 126 | |
fea681da MK |
127 | The externals |
128 | .I sys_nerr | |
129 | and | |
130 | .I sys_errlist | |
98ed7d1d | 131 | derive from BSD, but are not specified in POSIX.1. |
19c98696 | 132 | .SH NOTES |
fea681da MK |
133 | The externals |
134 | .I sys_nerr | |
135 | and | |
136 | .I sys_errlist | |
137 | are defined by glibc, but in | |
138 | .IR <stdio.h> . | |
139 | .\" and only when _BSD_SOURCE is defined. | |
c3dfd2c8 | 140 | .\" When |
cc4615cc MK |
141 | .\" .B _GNU_SOURCE |
142 | .\" is defined, the symbols | |
fea681da MK |
143 | .\" .I _sys_nerr |
144 | .\" and | |
145 | .\" .I _sys_errlist | |
146 | .\" are provided. | |
47297adb | 147 | .SH SEE ALSO |
d7871cf9 | 148 | .BR err (3), |
fea681da | 149 | .BR errno (3), |
37b6aec3 | 150 | .BR error (3), |
fea681da | 151 | .BR strerror (3) |