]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strerror.3
sync
[thirdparty/man-pages.git] / man3 / strerror.3
CommitLineData
fea681da 1.\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
1130df60 2.\" and Copyright (C) 2005, Michael Kerrisk <mtk-manpages@gmx.net>
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.
12.\"
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.
20.\"
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.\"
6e84dfa1 37.TH STRERROR 3 2005-12-13 "" "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
6e84dfa1
MK
46.BI "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen );
47 /* GNU-specific strerror_r() */
48.sp
49.B #define _XOPEN_SOURCE 600
b99cf1e0
MK
50.B #include <string.h>
51.sp
6e84dfa1
MK
52.BI "int strerror_r(int " errnum ", char *" buf ", size_t " buflen );
53 /* XSI-compliant strerror_r() */
fea681da
MK
54.fi
55.SH DESCRIPTION
63aa9df0 56The \fBstrerror\fP() function returns a string describing the error
fea681da
MK
57code passed in the argument \fIerrnum\fP, possibly using the LC_MESSAGES
58part of the current locale to select the appropriate language.
59This string must not be modified by the application, but may be
63aa9df0 60modified by a subsequent call to \fBperror\fP() or \fBstrerror\fP().
fea681da
MK
61No library function will modify this string.
62
63aa9df0 63The \fBstrerror_r\fP() function is similar to \fBstrerror\fP(), but is
6e84dfa1
MK
64thread safe.
65This function is available in two versions:
68e1685c 66an XSI-compliant version specified in POSIX.1-2001,
6e84dfa1
MK
67and a GNU-specific version (available since glibc 2.0).
68If _XOPEN_SOURCE is defined with the value 600,
69then the XSI-compliant version is provided,
70otherwise the GNU-specific version is provided.
71
72The XSI-compliant
73.BR strerror_r ()
74is preferred for portable applications.
75It returns the error string in the user-supplied buffer
fea681da
MK
76.I buf
77of length
6e84dfa1
MK
78.IR buflen .
79
80The GNU-specific
81.BR strerror_r ()
82returns a pointer to a string containing the error message.
83This may be either a pointer to a string that the function stores in
84.IR buf ,
85or a pointer to some (immutable) static string
86(in which case
87.I buf
88is unused).
89If the function stores a string in
90.IR buf ,
91then at most
92.I buflen
93bytes are stored (the string may be truncated if
94.I buflen
95is too small) and the string always includes a terminating null byte.
fea681da 96.SH "RETURN VALUE"
ed07f09a 97The \fBstrerror\fP() and \fBstrerror_r\fP() functions return
6e84dfa1
MK
98the appropriate error description string,
99or an "Unknown error nnn" message if the error number is unknown.
6e84dfa1
MK
100
101The XSI-compliant \fBstrerror_r\fP() function returns 0 on success;
102on error, \-1 is returned and
103.I errno
104is set to indicate the error.
fea681da
MK
105.SH ERRORS
106.TP
107.B EINVAL
108The value of
109.I errnum
110is not a valid error number.
111.TP
112.B ERANGE
113Insufficient storage was supplied to contain the error description string.
fea681da 114.SH "CONFORMING TO"
1eb85d14
MK
115\fBstrerror\fP() is specified by POSIX.1-2001, C89, C99.
116\fBstrerror_r\fP() is specified by POSIX.1-2001.
6e84dfa1
MK
117
118The GNU-specific
63aa9df0 119.BR strerror_r ()
6e84dfa1
MK
120function is a non-standard extension.
121
68e1685c 122POSIX.1-2001 permits
6e84dfa1
MK
123.BR strerror ()
124to set
125.I errno
126if the call encounters an error, but does not specify what
127value should be returned as the function result in the event of an error.
128On some systems,
129.\" e.g., Solaris 8, HP-UX 11
130.BR strerror ()
131returns NULL if the error number is unknown.
132On other systems,
133.\" e.g., FreeBSD 5.4, Tru64 5.1B
134.BR strerror ()
135returns a string something like "Error nnn occurred" and sets
136.I errno
137to
138.B EINVAL
139if the error number is unknown.
fea681da 140.SH "SEE ALSO"
d7871cf9 141.BR err (3),
fea681da 142.BR errno (3),
37b6aec3 143.BR error (3),
fea681da 144.BR perror (3),
0a90178c
MK
145.BR strsignal (3),
146.BR feature_test_macros (7)