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