]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/perror.3
Maintenance scripts
[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.\"
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.\"
30.TH PERROR 3 2001-12-14 "" "Library functions"
31.SH NAME
32perror \- 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
46The routine
47.B perror()
48produces a message on the standard error output, describing the last
49error encountered during a call to a system or library function.
50First (if
51.I s
52is not NULL and
53.RI * s
54is not NUL) the argument string
55.I s
56is printed, followed by a colon and a blank.
57Then the message and a new-line.
58
59To be of most use, the argument string should include the name
60of the function that incurred the error. The error number is taken from
61the external variable
62.IR errno ,
63which is set when errors occur but not
64cleared when non-erroneous calls are made.
65
66The global error list
67.IR sys_errlist "[]"
68indexed by
69.I errno
70can be used to obtain the error message without the newline.
71The largest message number provided in the table is
72.IR sys_nerr " \-1."
73Be careful when directly accessing this list because new error values
74may not have been added to
75.IR sys_errlist "[]."
76
77When a system call fails, it usually returns \-1 and sets the
78variable
79.I errno
80to a value describing what went wrong. (These values can be found in
81.IR "<errno.h>" .)
82Many library functions do likewise.
83The function
84.B perror()
85serves to translate this error code into human-readable form.
86Note that
87.I errno
88is undefined after a successful library call:
89this call may well change this variable, even though it succeeds,
90for example because it internally used some other library function that failed.
91Thus, if a failing call is not immediately followed by a call to
92.BR perror ,
93the value of
94.I errno
95should be saved.
96
97.SH "CONFORMING TO"
98The function
99.B perror()
100and the external
101.I errno
102(see
103.BR errno (3))
b14d4aa5 104conform to ANSI C, 4.3BSD, POSIX, X/OPEN.
fea681da
MK
105The externals
106.I sys_nerr
107and
108.I sys_errlist
109conform to BSD.
110.SH NOTE
111The externals
112.I sys_nerr
113and
114.I sys_errlist
115are defined by glibc, but in
116.IR <stdio.h> .
117.\" and only when _BSD_SOURCE is defined.
118.\" When _GNU_SOURCE is defined, the symbols
119.\" .I _sys_nerr
120.\" and
121.\" .I _sys_errlist
122.\" are provided.
123.SH "SEE ALSO"
124.BR errno (3),
125.BR strerror (3)