]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/perror.3
75e6aa20eaccb4892974b6e1e93e933fea35c9df
[thirdparty/man-pages.git] / man3 / perror.3
1 '\" t
2 .\" Copyright (c) 1994 Michael Haardt (michael@moria.de), 1994-06-04
3 .\" Copyright (c) 1995 Michael Haardt
4 .\" (michael@cantor.informatik.rwth-aachen.de), 1995-03-16
5 .\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl), 1996-01-13
6 .\"
7 .\" SPDX-License-Identifier: GPL-2.0-or-later
8 .\"
9 .\" 1996-01-13 aeb: merged in some text contributed by Melvin Smith
10 .\" (msmith@falcon.mercer.peachnet.edu) and various other changes.
11 .\" Modified 1996-05-16 by Martin Schulze (joey@infodrom.north.de)
12 .\"
13 .TH perror 3 (date) "Linux man-pages (unreleased)"
14 .SH NAME
15 perror \- print a system error message
16 .SH LIBRARY
17 Standard C library
18 .RI ( libc ", " \-lc )
19 .SH SYNOPSIS
20 .nf
21 .B #include <stdio.h>
22 .PP
23 .BI "void perror(const char *" s );
24 .PP
25 .B #include <errno.h>
26 .PP
27 .BI "int " errno "; \fR/* Not really declared this way; see errno(3) */"
28 .PP
29 .BI "[[deprecated]] const char *const " sys_errlist [];
30 .BI "[[deprecated]] int " sys_nerr ;
31 .fi
32 .PP
33 .RS -4
34 Feature Test Macro Requirements for glibc (see
35 .BR feature_test_macros (7)):
36 .RE
37 .PP
38 .IR sys_errlist ,
39 .IR sys_nerr :
40 .nf
41 From glibc 2.19 to glibc 2.31:
42 _DEFAULT_SOURCE
43 glibc 2.19 and earlier:
44 _BSD_SOURCE
45 .fi
46 .SH DESCRIPTION
47 The
48 .BR perror ()
49 function produces a message on standard error describing the last
50 error encountered during a call to a system or library function.
51 .PP
52 First (if
53 .I s
54 is not NULL and
55 .I *s
56 is not a null byte (\[aq]\e0\[aq])), the argument string
57 .I s
58 is printed, followed by a colon and a blank.
59 Then an error message corresponding to the current value of
60 .I errno
61 and a new-line.
62 .PP
63 To be of most use, the argument string should include the name
64 of the function that incurred the error.
65 .PP
66 The global error list
67 .IR sys_errlist "[],"
68 which can be indexed by
69 .IR errno ,
70 can be used to obtain the error message without the newline.
71 The largest message number provided in the table is
72 .IR sys_nerr "\-1."
73 Be careful when directly accessing this list, because new error values
74 may not have been added to
75 .IR sys_errlist "[]."
76 The use of
77 .IR sys_errlist "[]"
78 is nowadays deprecated; use
79 .BR strerror (3)
80 instead.
81 .PP
82 When a system call fails, it usually returns \-1 and sets the
83 variable
84 .I errno
85 to a value describing what went wrong.
86 (These values can be found in
87 .IR <errno.h> .)
88 Many library functions do likewise.
89 The function
90 .BR perror ()
91 serves to translate this error code into human-readable form.
92 Note that
93 .I errno
94 is undefined after a successful system call or library function call:
95 this call may well change this variable, even though it succeeds,
96 for example because it internally used some other library function that failed.
97 Thus, if a failing call is not immediately followed by a call to
98 .BR perror (),
99 the value of
100 .I errno
101 should be saved.
102 .SH ATTRIBUTES
103 For an explanation of the terms used in this section, see
104 .BR attributes (7).
105 .ad l
106 .nh
107 .TS
108 allbox;
109 lbx lb lb
110 l l l.
111 Interface Attribute Value
112 T{
113 .BR perror ()
114 T} Thread safety MT-Safe race:stderr
115 .TE
116 .hy
117 .ad
118 .sp 1
119 .SH STANDARDS
120 .TP
121 .I errno
122 .TQ
123 .BR perror ()
124 C11, POSIX.1-2008.
125 .TP
126 .I sys_nerr
127 .TQ
128 .I sys_errlist
129 BSD.
130 .SH HISTORY
131 .TP
132 .I errno
133 .TQ
134 .BR perror ()
135 POSIX.1-2001, C89, 4.3BSD.
136 .TP
137 .I sys_nerr
138 .TQ
139 .I sys_errlist
140 Removed in glibc 2.32.
141 .SH SEE ALSO
142 .BR err (3),
143 .BR errno (3),
144 .BR error (3),
145 .BR strerror (3)