]>
Commit | Line | Data |
---|---|---|
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 | .\" |
cc4615cc | 37 | .TH STRERROR 3 2007-07-26 "" "Linux Programmer's Manual" |
fea681da | 38 | .SH NAME |
6e84dfa1 | 39 | strerror, 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 | 46 | .BI "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen ); |
cc4615cc | 47 | .fi |
6e84dfa1 | 48 | .sp |
cc4615cc MK |
49 | .in -4n |
50 | Feature Test Macro Requirements for glibc (see | |
51 | .BR feature_test_macros (7)): | |
52 | .in | |
b99cf1e0 | 53 | .sp |
cc4615cc MK |
54 | The XSI-compliant version of |
55 | .BR strerror_r () | |
56 | is provided if: | |
57 | .br | |
58 | (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !\ _GNU_SOURCE | |
fea681da | 59 | .SH DESCRIPTION |
60a90ecd MK |
60 | The |
61 | .BR strerror () | |
62 | function returns a string describing the error | |
fea681da MK |
63 | code passed in the argument \fIerrnum\fP, possibly using the LC_MESSAGES |
64 | part of the current locale to select the appropriate language. | |
65 | This string must not be modified by the application, but may be | |
60a90ecd MK |
66 | modified by a subsequent call to |
67 | .BR perror (3) | |
68 | or | |
69 | .BR strerror (). | |
fea681da MK |
70 | No library function will modify this string. |
71 | ||
60a90ecd MK |
72 | The |
73 | .BR strerror_r () | |
74 | function is similar to | |
75 | .BR strerror (), | |
76 | but is | |
c13182ef MK |
77 | thread safe. |
78 | This function is available in two versions: | |
cc4615cc MK |
79 | an XSI-compliant version specified in POSIX.1-2001 |
80 | (available since glibc 2.3.4), | |
6e84dfa1 | 81 | and a GNU-specific version (available since glibc 2.0). |
cc4615cc MK |
82 | The XSI-compliant version is provided with the feature test macros |
83 | settings shown in the SYNOPSIS; | |
6e84dfa1 | 84 | otherwise the GNU-specific version is provided. |
cc4615cc MK |
85 | If no feature test macros are explicitly defined, |
86 | then (since glibc 2.4) | |
0daa9e92 | 87 | .B _POSIX_SOURCE |
cc4615cc MK |
88 | is defined by default with the value |
89 | 200112L, so that the XSI-compliant version of | |
90 | .BR strerror_r () | |
91 | is provided by default. | |
6e84dfa1 | 92 | |
c13182ef MK |
93 | The XSI-compliant |
94 | .BR strerror_r () | |
6e84dfa1 MK |
95 | is preferred for portable applications. |
96 | It returns the error string in the user-supplied buffer | |
fea681da MK |
97 | .I buf |
98 | of length | |
6e84dfa1 MK |
99 | .IR buflen . |
100 | ||
c13182ef MK |
101 | The GNU-specific |
102 | .BR strerror_r () | |
6e84dfa1 MK |
103 | returns a pointer to a string containing the error message. |
104 | This may be either a pointer to a string that the function stores in | |
105 | .IR buf , | |
106 | or a pointer to some (immutable) static string | |
107 | (in which case | |
c13182ef | 108 | .I buf |
6e84dfa1 | 109 | is unused). |
c13182ef | 110 | If the function stores a string in |
6e84dfa1 MK |
111 | .IR buf , |
112 | then at most | |
113 | .I buflen | |
114 | bytes are stored (the string may be truncated if | |
115 | .I buflen | |
116 | is too small) and the string always includes a terminating null byte. | |
fea681da | 117 | .SH "RETURN VALUE" |
60a90ecd MK |
118 | The |
119 | .BR strerror () | |
120 | and | |
121 | .BR strerror_r () | |
122 | functions return | |
c13182ef | 123 | the appropriate error description string, |
6e84dfa1 | 124 | or an "Unknown error nnn" message if the error number is unknown. |
6e84dfa1 | 125 | |
60a90ecd MK |
126 | The XSI-compliant |
127 | .BR strerror_r () | |
128 | function returns 0 on success; | |
6e84dfa1 MK |
129 | on error, \-1 is returned and |
130 | .I errno | |
131 | is set to indicate the error. | |
fea681da MK |
132 | .SH ERRORS |
133 | .TP | |
134 | .B EINVAL | |
135 | The value of | |
136 | .I errnum | |
137 | is not a valid error number. | |
138 | .TP | |
139 | .B ERANGE | |
140 | Insufficient storage was supplied to contain the error description string. | |
fea681da | 141 | .SH "CONFORMING TO" |
60a90ecd MK |
142 | .BR strerror () |
143 | is specified by POSIX.1-2001, C89, C99. | |
144 | .BR strerror_r () | |
145 | is specified by POSIX.1-2001. | |
6e84dfa1 | 146 | |
c13182ef | 147 | The GNU-specific |
63aa9df0 | 148 | .BR strerror_r () |
6e84dfa1 MK |
149 | function is a non-standard extension. |
150 | ||
68e1685c | 151 | POSIX.1-2001 permits |
6e84dfa1 | 152 | .BR strerror () |
c13182ef | 153 | to set |
6e84dfa1 | 154 | .I errno |
c13182ef | 155 | if the call encounters an error, but does not specify what |
6e84dfa1 MK |
156 | value should be returned as the function result in the event of an error. |
157 | On some systems, | |
158 | .\" e.g., Solaris 8, HP-UX 11 | |
159 | .BR strerror () | |
160 | returns NULL if the error number is unknown. | |
c13182ef | 161 | On other systems, |
6e84dfa1 MK |
162 | .\" e.g., FreeBSD 5.4, Tru64 5.1B |
163 | .BR strerror () | |
c13182ef | 164 | returns a string something like "Error nnn occurred" and sets |
6e84dfa1 | 165 | .I errno |
c13182ef | 166 | to |
6e84dfa1 MK |
167 | .B EINVAL |
168 | if the error number is unknown. | |
fea681da | 169 | .SH "SEE ALSO" |
d7871cf9 | 170 | .BR err (3), |
fea681da | 171 | .BR errno (3), |
37b6aec3 | 172 | .BR error (3), |
fea681da | 173 | .BR perror (3), |
cc4615cc | 174 | .BR strsignal (3) |