]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strerror.3
pthread_testcancel.3: tfix
[thirdparty/man-pages.git] / man3 / strerror.3
CommitLineData
fea681da 1.\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
c11b1abf 2.\" and Copyright (C) 2005, Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
3.\"
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
c13182ef 12.\"
fea681da
MK
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
23.\"
24.\" References consulted:
25.\" Linux libc source code
26.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27.\" 386BSD man pages
28.\" Modified Sat Jul 24 18:05:30 1993 by Rik Faith <faith@cs.unc.edu>
29.\" Modified Fri Feb 16 14:25:17 1996 by Andries Brouwer <aeb@cwi.nl>
30.\" Modified Sun Jul 21 20:55:44 1996 by Andries Brouwer <aeb@cwi.nl>
31.\" Modified Mon Oct 15 21:16:25 2001 by John Levon <moz@compsoc.man.ac.uk>
32.\" Modified Tue Oct 16 00:04:43 2001 by Andries Brouwer <aeb@cwi.nl>
33.\" Modified Fri Jun 20 03:04:30 2003 by Andries Brouwer <aeb@cwi.nl>
ed07f09a
MK
34.\" 2005-12-13, mtk, Substantial rewrite of strerror_r() description
35.\" Addition of extra material on portability and standards.
fea681da 36.\"
a5fa6dfd 37.TH STRERROR 3 2012-04-22 "" "Linux Programmer's Manual"
fea681da 38.SH NAME
6e84dfa1 39strerror, strerror_r \- return string describing error number
fea681da
MK
40.SH SYNOPSIS
41.nf
42.B #include <string.h>
43.sp
44.BI "char *strerror(int " errnum );
b99cf1e0 45.sp
2d50dd9e
MK
46.BI "int strerror_r(int " errnum ", char *" buf ", size_t " buflen );
47 /* XSI-compliant */
48.sp
6e84dfa1 49.BI "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen );
2d50dd9e 50 /* GNU-specific */
cc4615cc 51.fi
6e84dfa1 52.sp
cc4615cc
MK
53.in -4n
54Feature Test Macro Requirements for glibc (see
55.BR feature_test_macros (7)):
56.in
b99cf1e0 57.sp
cc4615cc
MK
58The XSI-compliant version of
59.BR strerror_r ()
60is provided if:
61.br
98dbe7af 62(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600) && !\ _GNU_SOURCE
2d50dd9e
MK
63.br
64Otherwise, the GNU-specific version is provided.
fea681da 65.SH DESCRIPTION
60a90ecd
MK
66The
67.BR strerror ()
c9980d2e 68function returns a pointer to a string that describes the error
61d71e01
MK
69code passed in the argument
70.IR errnum ,
71possibly using the
ec5a588f 72.B LC_MESSAGES
fea681da 73part of the current locale to select the appropriate language.
6fb29ca0
MK
74(For example, if
75.I errnum
76is
77.BR EINVAL ,
78the returned description will "Invalid argument".)
fea681da 79This string must not be modified by the application, but may be
60a90ecd 80modified by a subsequent call to
60a90ecd 81.BR strerror ().
8ca6ceb0
EB
82No library function, including
83.BR perror (3),
84will modify this string.
fea681da 85
60a90ecd
MK
86The
87.BR strerror_r ()
88function is similar to
89.BR strerror (),
90but is
c13182ef
MK
91thread safe.
92This function is available in two versions:
cc4615cc 93an XSI-compliant version specified in POSIX.1-2001
8ca6ceb0 94(available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13),
6e84dfa1 95and a GNU-specific version (available since glibc 2.0).
cc4615cc
MK
96The XSI-compliant version is provided with the feature test macros
97settings shown in the SYNOPSIS;
6e84dfa1 98otherwise the GNU-specific version is provided.
cc4615cc
MK
99If no feature test macros are explicitly defined,
100then (since glibc 2.4)
0daa9e92 101.B _POSIX_SOURCE
cc4615cc
MK
102is defined by default with the value
103200112L, so that the XSI-compliant version of
104.BR strerror_r ()
105is provided by default.
6e84dfa1 106
c13182ef
MK
107The XSI-compliant
108.BR strerror_r ()
6e84dfa1
MK
109is preferred for portable applications.
110It returns the error string in the user-supplied buffer
fea681da
MK
111.I buf
112of length
6e84dfa1
MK
113.IR buflen .
114
c13182ef
MK
115The GNU-specific
116.BR strerror_r ()
6e84dfa1
MK
117returns a pointer to a string containing the error message.
118This may be either a pointer to a string that the function stores in
119.IR buf ,
120or a pointer to some (immutable) static string
121(in which case
c13182ef 122.I buf
6e84dfa1 123is unused).
c13182ef 124If the function stores a string in
6e84dfa1
MK
125.IR buf ,
126then at most
127.I buflen
128bytes are stored (the string may be truncated if
129.I buflen
8ca6ceb0
EB
130is too small and
131.I errnum
132is unknown).
133The string always includes a terminating null byte.
fea681da 134.SH "RETURN VALUE"
60a90ecd
MK
135The
136.BR strerror ()
2d50dd9e 137and the GNU-specific
60a90ecd
MK
138.BR strerror_r ()
139functions return
c13182ef 140the appropriate error description string,
6e84dfa1 141or an "Unknown error nnn" message if the error number is unknown.
6e84dfa1 142
f2682520
MK
143POSIX.1-2001 and POSIX.1-2008 require that a successful call to
144.BR strerror (3)
145shall leave
146.I errno
147unchanged, and note that,
148since no function return value is reserved to indicate an error,
149an application that wishes to check for errors should initialize
150.I errno
151to zero before the call,
152and then check
153.I errno
154after the call.
155
60a90ecd
MK
156The XSI-compliant
157.BR strerror_r ()
8ca6ceb0
EB
158function returns 0 on success.
159On error,
160a (positive) error number is returned (since glibc 2.13),
161or \-1 is returned and
162.I errno
163is set to indicate the error (glibc versions before 2.13).
fea681da
MK
164.SH ERRORS
165.TP
166.B EINVAL
167The value of
168.I errnum
169is not a valid error number.
170.TP
171.B ERANGE
172Insufficient storage was supplied to contain the error description string.
fea681da 173.SH "CONFORMING TO"
60a90ecd
MK
174.BR strerror ()
175is specified by POSIX.1-2001, C89, C99.
176.BR strerror_r ()
177is specified by POSIX.1-2001.
6e84dfa1 178
c13182ef 179The GNU-specific
63aa9df0 180.BR strerror_r ()
c8f2dd47 181function is a nonstandard extension.
6e84dfa1 182
68e1685c 183POSIX.1-2001 permits
6e84dfa1 184.BR strerror ()
c13182ef 185to set
6e84dfa1 186.I errno
c13182ef 187if the call encounters an error, but does not specify what
6e84dfa1
MK
188value should be returned as the function result in the event of an error.
189On some systems,
190.\" e.g., Solaris 8, HP-UX 11
191.BR strerror ()
192returns NULL if the error number is unknown.
c13182ef 193On other systems,
6e84dfa1
MK
194.\" e.g., FreeBSD 5.4, Tru64 5.1B
195.BR strerror ()
c13182ef 196returns a string something like "Error nnn occurred" and sets
6e84dfa1 197.I errno
c13182ef 198to
6e84dfa1
MK
199.B EINVAL
200if the error number is unknown.
8ca6ceb0 201C99 and POSIX.1-2008 require the return value to be non-NULL.
fea681da 202.SH "SEE ALSO"
d7871cf9 203.BR err (3),
fea681da 204.BR errno (3),
37b6aec3 205.BR error (3),
fea681da 206.BR perror (3),
cc4615cc 207.BR strsignal (3)