]>
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 | .\" | |
6 | .\" This is free documentation; you can redistribute it and/or | |
7 | .\" modify it under the terms of the GNU General Public License as | |
8 | .\" published by the Free Software Foundation; either version 2 of | |
9 | .\" the License, or (at your option) any later version. | |
10 | .\" | |
11 | .\" The GNU General Public License's references to "object code" | |
12 | .\" and "executables" are to be interpreted as the output of any | |
13 | .\" document formatting or typesetting system, including | |
14 | .\" intermediate and printed output. | |
15 | .\" | |
16 | .\" This manual is distributed in the hope that it will be useful, | |
17 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | .\" GNU General Public License for more details. | |
20 | .\" | |
21 | .\" You should have received a copy of the GNU General Public | |
22 | .\" License along with this manual; if not, write to the Free | |
23 | .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, | |
24 | .\" USA. | |
25 | .\" | |
26 | .\" 1996-01-13 aeb: merged in some text contributed by Melvin Smith | |
27 | .\" (msmith@falcon.mercer.peachnet.edu) and various other changes. | |
28 | .\" Modified 1996-05-16 by Martin Schulze (joey@infodrom.north.de) | |
29 | .\" | |
0ed55ece | 30 | .TH PERROR 3 2001-12-14 "" "Linux Programmer's Manual" |
fea681da MK |
31 | .SH NAME |
32 | perror \- print a system error message | |
33 | .SH SYNOPSIS | |
34 | .B #include <stdio.h> | |
35 | .sp | |
36 | .BI "void perror(const char " *s ); | |
37 | .sp | |
38 | .B #include <errno.h> | |
39 | .sp | |
40 | .BI "const char *" sys_errlist []; | |
41 | .br | |
42 | .BI "int " sys_nerr ; | |
43 | .br | |
44 | .BI "int " errno ; | |
45 | .SH DESCRIPTION | |
46 | The routine | |
63aa9df0 | 47 | .BR perror () |
fea681da MK |
48 | produces a message on the standard error output, describing the last |
49 | error encountered during a call to a system or library function. | |
50 | First (if | |
51 | .I s | |
52 | is not NULL and | |
53 | .RI * s | |
28d88c17 | 54 | is not a null byte ('\\0')) the argument string |
fea681da MK |
55 | .I s |
56 | is printed, followed by a colon and a blank. | |
57 | Then the message and a new-line. | |
58 | ||
59 | To be of most use, the argument string should include the name | |
c13182ef MK |
60 | of the function that incurred the error. |
61 | The error number is taken from | |
fea681da MK |
62 | the external variable |
63 | .IR errno , | |
64 | which is set when errors occur but not | |
65 | cleared when non-erroneous calls are made. | |
66 | ||
67 | The global error list | |
68 | .IR sys_errlist "[]" | |
69 | indexed by | |
70 | .I errno | |
71 | can be used to obtain the error message without the newline. | |
72 | The largest message number provided in the table is | |
73 | .IR sys_nerr " \-1." | |
74 | Be careful when directly accessing this list because new error values | |
75 | may not have been added to | |
76 | .IR sys_errlist "[]." | |
77 | ||
78 | When a system call fails, it usually returns \-1 and sets the | |
79 | variable | |
80 | .I errno | |
c13182ef MK |
81 | to a value describing what went wrong. |
82 | (These values can be found in | |
fea681da MK |
83 | .IR "<errno.h>" .) |
84 | Many library functions do likewise. | |
85 | The function | |
63aa9df0 | 86 | .BR perror () |
fea681da MK |
87 | serves to translate this error code into human-readable form. |
88 | Note that | |
89 | .I errno | |
90 | is undefined after a successful library call: | |
91 | this call may well change this variable, even though it succeeds, | |
92 | for example because it internally used some other library function that failed. | |
93 | Thus, if a failing call is not immediately followed by a call to | |
e511ffb6 | 94 | .BR perror (), |
fea681da MK |
95 | the value of |
96 | .I errno | |
97 | should be saved. | |
fea681da MK |
98 | .SH "CONFORMING TO" |
99 | The function | |
63aa9df0 | 100 | .BR perror () |
fea681da MK |
101 | and the external |
102 | .I errno | |
103 | (see | |
104 | .BR errno (3)) | |
1eb85d14 | 105 | conform to C89, C99, 4.3BSD, POSIX.1-2001. |
fea681da MK |
106 | The externals |
107 | .I sys_nerr | |
108 | and | |
109 | .I sys_errlist | |
110 | conform to BSD. | |
19c98696 | 111 | .SH NOTES |
fea681da MK |
112 | The externals |
113 | .I sys_nerr | |
114 | and | |
115 | .I sys_errlist | |
116 | are defined by glibc, but in | |
117 | .IR <stdio.h> . | |
118 | .\" and only when _BSD_SOURCE is defined. | |
119 | .\" When _GNU_SOURCE is defined, the symbols | |
120 | .\" .I _sys_nerr | |
121 | .\" and | |
122 | .\" .I _sys_errlist | |
123 | .\" are provided. | |
124 | .SH "SEE ALSO" | |
d7871cf9 | 125 | .BR err (3), |
fea681da | 126 | .BR errno (3), |
37b6aec3 | 127 | .BR error (3), |
fea681da | 128 | .BR strerror (3) |