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