]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strerror.3
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man3 / strerror.3
CommitLineData
fea681da 1.\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
d2c55aa7 2.\" and Copyright (C) 2005, 2014, 2020 Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 3.\"
5fbde956 4.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
5.\"
6.\" References consulted:
7.\" Linux libc source code
8.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9.\" 386BSD man pages
10.\" Modified Sat Jul 24 18:05:30 1993 by Rik Faith <faith@cs.unc.edu>
11.\" Modified Fri Feb 16 14:25:17 1996 by Andries Brouwer <aeb@cwi.nl>
12.\" Modified Sun Jul 21 20:55:44 1996 by Andries Brouwer <aeb@cwi.nl>
13.\" Modified Mon Oct 15 21:16:25 2001 by John Levon <moz@compsoc.man.ac.uk>
14.\" Modified Tue Oct 16 00:04:43 2001 by Andries Brouwer <aeb@cwi.nl>
15.\" Modified Fri Jun 20 03:04:30 2003 by Andries Brouwer <aeb@cwi.nl>
ed07f09a
MK
16.\" 2005-12-13, mtk, Substantial rewrite of strerror_r() description
17.\" Addition of extra material on portability and standards.
fea681da 18.\"
1ae6b2c7 19.TH STRERROR 3 2021-03-22 GNU "Linux Programmer's Manual"
fea681da 20.SH NAME
d2c55aa7 21strerror, strerrorname_np, strerrordesc_np, strerror_r, strerror_l \- return string describing error number
45d84983
AC
22.SH LIBRARY
23Standard C library
8fc3b2cf 24.RI ( libc ", " \-lc )
fea681da
MK
25.SH SYNOPSIS
26.nf
27.B #include <string.h>
68e4db0a 28.PP
fea681da 29.BI "char *strerror(int " errnum );
d2c55aa7
MK
30.BI "const char *strerrorname_np(int " errnum );
31.BI "const char *strerrordesc_np(int " errnum );
68e4db0a 32.PP
2d50dd9e 33.BI "int strerror_r(int " errnum ", char *" buf ", size_t " buflen );
f2667a72 34 /* XSI-compliant */
68e4db0a 35.PP
6e84dfa1 36.BI "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen );
f2667a72 37 /* GNU-specific */
dbfe9c70 38.PP
103357f7 39.BI "char *strerror_l(int " errnum ", locale_t " locale );
cc4615cc 40.fi
68e4db0a 41.PP
d39ad78f 42.RS -4
cc4615cc
MK
43Feature Test Macro Requirements for glibc (see
44.BR feature_test_macros (7)):
d39ad78f 45.RE
68e4db0a 46.PP
d2c55aa7
MK
47.BR strerrorname_np (),
48.BR strerrordesc_np ():
9d2adbae 49.nf
d2c55aa7 50 _GNU_SOURCE
9d2adbae 51.fi
d2c55aa7 52.PP
103357f7 53.BR strerror_r ():
9d2adbae
MK
54.nf
55 The XSI-compliant version is provided if:
5c10d2c5 56 (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
9d2adbae
MK
57 Otherwise, the GNU-specific version is provided.
58.fi
fea681da 59.SH DESCRIPTION
60a90ecd
MK
60The
61.BR strerror ()
c9980d2e 62function returns a pointer to a string that describes the error
61d71e01
MK
63code passed in the argument
64.IR errnum ,
65possibly using the
ec5a588f 66.B LC_MESSAGES
fea681da 67part of the current locale to select the appropriate language.
6fb29ca0
MK
68(For example, if
69.I errnum
70is
71.BR EINVAL ,
926fc5d5 72the returned description will be "Invalid argument".)
fea681da 73This string must not be modified by the application, but may be
60a90ecd 74modified by a subsequent call to
103357f7
MK
75.BR strerror ()
76or
77.BR strerror_l ().
c99c1440 78No other library function, including
8ca6ceb0
EB
79.BR perror (3),
80will modify this string.
d2c55aa7
MK
81.PP
82Like
83.BR strerror (),
84the
85.BR strerrordesc_np ()
86function returns a pointer to a string that describes the error
87code passed in the argument
88.IR errnum ,
89with the difference that the returned string is not translated
90according to the current locale.
91.PP
92The
93.BR strerrorname_np ()
94function returns a pointer to a string containing the name of the error
95code passed in the argument
96.IR errnum .
97For example, given
1ae6b2c7 98.B EPERM
d2c55aa7 99as an argument, this function returns a pointer to the string "EPERM".
103357f7 100.\"
5b436d02 101.SS strerror_r()
60a90ecd
MK
102The
103.BR strerror_r ()
104function is similar to
105.BR strerror (),
106but is
c13182ef
MK
107thread safe.
108This function is available in two versions:
cc4615cc 109an XSI-compliant version specified in POSIX.1-2001
8ca6ceb0 110(available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13),
6e84dfa1 111and a GNU-specific version (available since glibc 2.0).
cc4615cc
MK
112The XSI-compliant version is provided with the feature test macros
113settings shown in the SYNOPSIS;
6e84dfa1 114otherwise the GNU-specific version is provided.
cc4615cc
MK
115If no feature test macros are explicitly defined,
116then (since glibc 2.4)
c4a256e2 117.B _POSIX_C_SOURCE
cc4615cc
MK
118is defined by default with the value
119200112L, so that the XSI-compliant version of
120.BR strerror_r ()
121is provided by default.
847e0d88 122.PP
c13182ef
MK
123The XSI-compliant
124.BR strerror_r ()
6e84dfa1
MK
125is preferred for portable applications.
126It returns the error string in the user-supplied buffer
fea681da
MK
127.I buf
128of length
6e84dfa1 129.IR buflen .
847e0d88 130.PP
c13182ef
MK
131The GNU-specific
132.BR strerror_r ()
6e84dfa1
MK
133returns a pointer to a string containing the error message.
134This may be either a pointer to a string that the function stores in
135.IR buf ,
136or a pointer to some (immutable) static string
137(in which case
c13182ef 138.I buf
6e84dfa1 139is unused).
c13182ef 140If the function stores a string in
6e84dfa1
MK
141.IR buf ,
142then at most
143.I buflen
144bytes are stored (the string may be truncated if
145.I buflen
8ca6ceb0
EB
146is too small and
147.I errnum
148is unknown).
d1a71985 149The string always includes a terminating null byte (\(aq\e0\(aq).
103357f7
MK
150.\"
151.SS strerror_l()
152.BR strerror_l ()
153is like
154.BR strerror (),
155but maps
156.I errnum
157to a locale-dependent error message in the locale specified by
158.IR locale .
159The behavior of
160.BR strerror_l ()
161is undefined if
162.I locale
163is the special locale object
1ae6b2c7 164.B LC_GLOBAL_LOCALE
103357f7 165or is not a valid locale object handle.
47297adb 166.SH RETURN VALUE
60a90ecd 167The
103357f7
MK
168.BR strerror (),
169.BR strerror_l (),
2d50dd9e 170and the GNU-specific
60a90ecd
MK
171.BR strerror_r ()
172functions return
c13182ef 173the appropriate error description string,
6e84dfa1 174or an "Unknown error nnn" message if the error number is unknown.
847e0d88 175.PP
d2c55aa7
MK
176On success,
177.BR strerrorname_np ()
178and
179.BR strerrordesc_np ()
180return the appropriate error description string.
181If
182.I errnum
183is an invalid error number, these functions return NULL.
184.PP
103357f7
MK
185The XSI-compliant
186.BR strerror_r ()
187function returns 0 on success.
188On error,
189a (positive) error number is returned (since glibc 2.13),
190or \-1 is returned and
191.I errno
192is set to indicate the error (glibc versions before 2.13).
847e0d88 193.PP
f2682520 194POSIX.1-2001 and POSIX.1-2008 require that a successful call to
563f4681 195.BR strerror ()
103357f7
MK
196or
197.BR strerror_l ()
f2682520
MK
198shall leave
199.I errno
200unchanged, and note that,
201since no function return value is reserved to indicate an error,
202an application that wishes to check for errors should initialize
203.I errno
204to zero before the call,
205and then check
206.I errno
207after the call.
fea681da
MK
208.SH ERRORS
209.TP
210.B EINVAL
211The value of
212.I errnum
213is not a valid error number.
214.TP
215.B ERANGE
216Insufficient storage was supplied to contain the error description string.
bdec6fb0
MK
217.SH VERSIONS
218The
219.BR strerror_l ()
220function first appeared in glibc 2.6.
fb0390dc
AC
221.PP
222The
223.BR strerrorname_np ()
224and
225.BR strerrordesc_np ()
226functions first appeared in glibc 2.32.
18b3fa61 227.SH ATTRIBUTES
9cf2aed1
PH
228For an explanation of the terms used in this section, see
229.BR attributes (7).
c466875e
MK
230.ad l
231.nh
9cf2aed1
PH
232.TS
233allbox;
b32feea5 234lb lb lbx
9cf2aed1
PH
235l l l.
236Interface Attribute Value
237T{
18b3fa61 238.BR strerror ()
b32feea5
MK
239T} Thread safety T{
240MT-Unsafe race:strerror
241T}
9cf2aed1 242T{
d2c55aa7 243.BR strerrorname_np (),
73cf5b83 244.BR strerrordesc_np ()
d2c55aa7
MK
245T} Thread safety MT-Safe
246T{
9cf2aed1
PH
247.BR strerror_r (),
248.BR strerror_l ()
249T} Thread safety MT-Safe
250.TE
c466875e
MK
251.hy
252.ad
253.sp 1
47297adb 254.SH CONFORMING TO
60a90ecd 255.BR strerror ()
b0bcb0ad 256is specified by POSIX.1-2001, POSIX.1-2008, C89, and C99.
60a90ecd 257.BR strerror_r ()
b0bcb0ad 258is specified by POSIX.1-2001 and POSIX.1-2008.
eaa8868c
MK
259.\" FIXME . for later review when Issue 8 is one day released...
260.\" A future POSIX.1 may remove strerror_r()
261.\" http://austingroupbugs.net/tag_view_page.php?tag_id=8
262.\" http://austingroupbugs.net/view.php?id=508
847e0d88 263.PP
103357f7
MK
264.BR strerror_l ()
265is specified in POSIX.1-2008.
847e0d88 266.PP
d2c55aa7
MK
267The GNU-specific functions
268.BR strerror_r (),
269.BR strerrorname_np (),
270and
271.BR strerrordesc_np ()
272are nonstandard extensions.
847e0d88 273.PP
68e1685c 274POSIX.1-2001 permits
6e84dfa1 275.BR strerror ()
c13182ef 276to set
6e84dfa1 277.I errno
c13182ef 278if the call encounters an error, but does not specify what
6e84dfa1
MK
279value should be returned as the function result in the event of an error.
280On some systems,
281.\" e.g., Solaris 8, HP-UX 11
282.BR strerror ()
283returns NULL if the error number is unknown.
c13182ef 284On other systems,
6e84dfa1
MK
285.\" e.g., FreeBSD 5.4, Tru64 5.1B
286.BR strerror ()
c13182ef 287returns a string something like "Error nnn occurred" and sets
6e84dfa1 288.I errno
c13182ef 289to
6e84dfa1
MK
290.B EINVAL
291if the error number is unknown.
8ca6ceb0 292C99 and POSIX.1-2008 require the return value to be non-NULL.
e9cf84ab 293.SH NOTES
5d048f53 294The GNU C Library uses a buffer of 1024 characters for
e9cf84ab 295.BR strerror ().
154e01af 296This buffer size therefore should be sufficient to avoid an
e9cf84ab 297.B ERANGE
5d048f53 298error when calling
9e6513b5 299.BR strerror_r ().
d2c55aa7
MK
300.PP
301.BR strerrorname_np ()
302and
303.BR strerrordesc_np ()
304are thread-safe and async-signal-safe.
47297adb 305.SH SEE ALSO
d7871cf9 306.BR err (3),
fea681da 307.BR errno (3),
37b6aec3 308.BR error (3),
fea681da 309.BR perror (3),
103357f7
MK
310.BR strsignal (3),
311.BR locale (7)