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