]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/perror.3
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex...
[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.\"
ffbe8907 30.TH PERROR 3 2012-04-17 "" "Linux Programmer's Manual"
fea681da
MK
31.SH NAME
32perror \- print a system error message
33.SH SYNOPSIS
34.B #include <stdio.h>
35.sp
01038eba 36.BI "void perror(const char *" s );
fea681da
MK
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 ;
cc4615cc
MK
45.sp
46.in -4n
47Feature Test Macro Requirements for glibc (see
48.BR feature_test_macros (7)):
49.in
50.sp
51.IR sys_errlist ,
52.IR sys_nerr :
53_BSD_SOURCE
fea681da
MK
54.SH DESCRIPTION
55The routine
63aa9df0 56.BR perror ()
fea681da
MK
57produces a message on the standard error output, describing the last
58error encountered during a call to a system or library function.
59First (if
60.I s
61is not NULL and
bd9b2a9c 62.I *s
f81fb444 63is not a null byte (\(aq\\0\(aq)) the argument string
fea681da
MK
64.I s
65is printed, followed by a colon and a blank.
66Then the message and a new-line.
67
68To be of most use, the argument string should include the name
c13182ef
MK
69of the function that incurred the error.
70The error number is taken from
fea681da
MK
71the external variable
72.IR errno ,
73which is set when errors occur but not
f52bc8cd 74cleared when successful calls are made.
fea681da
MK
75
76The global error list
77.IR sys_errlist "[]"
78indexed by
79.I errno
80can be used to obtain the error message without the newline.
81The largest message number provided in the table is
b29f2872 82.IR sys_nerr "\-1."
fea681da
MK
83Be careful when directly accessing this list because new error values
84may not have been added to
85.IR sys_errlist "[]."
79038fa7
MK
86The use of
87.IR sys_errlist "[]"
88is nowadays deprecated.
89
fea681da
MK
90
91When a system call fails, it usually returns \-1 and sets the
92variable
93.I errno
c13182ef
MK
94to a value describing what went wrong.
95(These values can be found in
a9a13a50 96.IR <errno.h> .)
fea681da
MK
97Many library functions do likewise.
98The function
63aa9df0 99.BR perror ()
fea681da
MK
100serves to translate this error code into human-readable form.
101Note that
102.I errno
103is undefined after a successful library call:
104this call may well change this variable, even though it succeeds,
105for example because it internally used some other library function that failed.
106Thus, if a failing call is not immediately followed by a call to
e511ffb6 107.BR perror (),
fea681da
MK
108the value of
109.I errno
110should be saved.
47297adb 111.SH CONFORMING TO
fea681da 112The function
63aa9df0 113.BR perror ()
fea681da
MK
114and the external
115.I errno
116(see
117.BR errno (3))
1eb85d14 118conform to C89, C99, 4.3BSD, POSIX.1-2001.
fea681da
MK
119The externals
120.I sys_nerr
121and
122.I sys_errlist
123conform to BSD.
19c98696 124.SH NOTES
fea681da
MK
125The externals
126.I sys_nerr
127and
128.I sys_errlist
129are defined by glibc, but in
130.IR <stdio.h> .
131.\" and only when _BSD_SOURCE is defined.
c3dfd2c8 132.\" When
cc4615cc
MK
133.\" .B _GNU_SOURCE
134.\" is defined, the symbols
fea681da
MK
135.\" .I _sys_nerr
136.\" and
137.\" .I _sys_errlist
138.\" are provided.
47297adb 139.SH SEE ALSO
d7871cf9 140.BR err (3),
fea681da 141.BR errno (3),
37b6aec3 142.BR error (3),
fea681da 143.BR strerror (3)