OSDN Git Service

facc10e7d3311ce6b283067da7f4ffe9d576d769
[linuxjm/LDP_man-pages.git] / original / 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 2012-04-17 "" "Linux Programmer's Manual"
32 .SH NAME
33 perror \- print a system error message
34 .SH SYNOPSIS
35 .B #include <stdio.h>
36 .sp
37 .BI "void perror(const char *" s );
38 .sp
39 .B #include <errno.h>
40 .sp
41 .BI "const char *" sys_errlist [];
42 .br
43 .BI "int " sys_nerr ;
44 .br
45 .BI "int " errno ;
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
55 .SH DESCRIPTION
56 The routine
57 .BR perror ()
58 produces a message on the standard error output, describing the last
59 error encountered during a call to a system or library function.
60 First (if
61 .I s
62 is not NULL and
63 .I *s
64 is not a null byte (\(aq\\0\(aq)) the argument string
65 .I s
66 is printed, followed by a colon and a blank.
67 Then the message and a new-line.
68
69 To be of most use, the argument string should include the name
70 of the function that incurred the error.
71 The error number is taken from
72 the external variable
73 .IR errno ,
74 which is set when errors occur but not
75 cleared when successful calls are made.
76
77 The global error list
78 .IR sys_errlist "[]"
79 indexed by
80 .I errno
81 can be used to obtain the error message without the newline.
82 The largest message number provided in the table is
83 .IR sys_nerr "\-1."
84 Be careful when directly accessing this list because new error values
85 may not have been added to
86 .IR sys_errlist "[]."
87 The use of
88 .IR sys_errlist "[]"
89 is nowadays deprecated.
90
91 When a system call fails, it usually returns \-1 and sets the
92 variable
93 .I errno
94 to a value describing what went wrong.
95 (These values can be found in
96 .IR <errno.h> .)
97 Many library functions do likewise.
98 The function
99 .BR perror ()
100 serves to translate this error code into human-readable form.
101 Note that
102 .I errno
103 is undefined after a successful library call:
104 this call may well change this variable, even though it succeeds,
105 for example because it internally used some other library function that failed.
106 Thus, if a failing call is not immediately followed by a call to
107 .BR perror (),
108 the value of
109 .I errno
110 should be saved.
111 .SH CONFORMING TO
112 The function
113 .BR perror ()
114 and the external
115 .I errno
116 (see
117 .BR errno (3))
118 conform to C89, C99, 4.3BSD, POSIX.1-2001.
119 The externals
120 .I sys_nerr
121 and
122 .I sys_errlist
123 conform to BSD.
124 .SH NOTES
125 The externals
126 .I sys_nerr
127 and
128 .I sys_errlist
129 are defined by glibc, but in
130 .IR <stdio.h> .
131 .\" and only when _BSD_SOURCE is defined.
132 .\" When
133 .\" .B _GNU_SOURCE
134 .\" is defined, the symbols
135 .\" .I _sys_nerr
136 .\" and
137 .\" .I _sys_errlist
138 .\" are provided.
139 .SH SEE ALSO
140 .BR err (3),
141 .BR errno (3),
142 .BR error (3),
143 .BR strerror (3)
144 .SH COLOPHON
145 This page is part of release 3.67 of the Linux
146 .I man-pages
147 project.
148 A description of the project,
149 information about reporting bugs,
150 and the latest version of this page,
151 can be found at
152 \%http://www.kernel.org/doc/man\-pages/.