OSDN Git Service

28ddb8197b3d37d940fd799089cb39235c486064
[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 .\" 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 2007-07-26 "" "Linux Programmer's Manual"
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 .sp
46 .in -4n
47 Feature 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
54 .SH DESCRIPTION
55 The routine
56 .BR perror ()
57 produces a message on the standard error output, describing the last
58 error encountered during a call to a system or library function.
59 First (if
60 .I s
61 is not NULL and
62 .I *s
63 is not a null byte (\(aq\\0\(aq)) the argument string
64 .I s
65 is printed, followed by a colon and a blank.
66 Then the message and a new-line.
67
68 To be of most use, the argument string should include the name
69 of the function that incurred the error.
70 The error number is taken from
71 the external variable
72 .IR errno ,
73 which is set when errors occur but not
74 cleared when successful calls are made.
75
76 The global error list
77 .IR sys_errlist "[]"
78 indexed by
79 .I errno
80 can be used to obtain the error message without the newline.
81 The largest message number provided in the table is
82 .IR sys_nerr " \-1."
83 Be careful when directly accessing this list because new error values
84 may not have been added to
85 .IR sys_errlist "[]."
86
87 When a system call fails, it usually returns \-1 and sets the
88 variable
89 .I errno
90 to a value describing what went wrong.
91 (These values can be found in
92 .IR <errno.h> .)
93 Many library functions do likewise.
94 The function
95 .BR perror ()
96 serves to translate this error code into human-readable form.
97 Note that
98 .I errno
99 is undefined after a successful library call:
100 this call may well change this variable, even though it succeeds,
101 for example because it internally used some other library function that failed.
102 Thus, if a failing call is not immediately followed by a call to
103 .BR perror (),
104 the value of
105 .I errno
106 should be saved.
107 .SH "CONFORMING TO"
108 The function
109 .BR perror ()
110 and the external
111 .I errno
112 (see
113 .BR errno (3))
114 conform to C89, C99, 4.3BSD, POSIX.1-2001.
115 The externals
116 .I sys_nerr
117 and
118 .I sys_errlist
119 conform to BSD.
120 .SH NOTES
121 The externals
122 .I sys_nerr
123 and
124 .I sys_errlist
125 are defined by glibc, but in
126 .IR <stdio.h> .
127 .\" and only when _BSD_SOURCE is defined.
128 .\" When
129 .\" .B _GNU_SOURCE
130 .\" is defined, the symbols
131 .\" .I _sys_nerr
132 .\" and
133 .\" .I _sys_errlist
134 .\" are provided.
135 .SH "SEE ALSO"
136 .BR err (3),
137 .BR errno (3),
138 .BR error (3),
139 .BR strerror (3)