1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2005, 2014, 2020 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" References consulted:
27 .\" Linux libc source code
28 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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>
36 .\" 2005-12-13, mtk, Substantial rewrite of strerror_r() description
37 .\" Addition of extra material on portability and standards.
39 .TH STRERROR 3 2021-03-22 "" "Linux Programmer's Manual"
41 strerror, strerrorname_np, strerrordesc_np, strerror_r, strerror_l \- return string describing error number
44 .B #include <string.h>
46 .BI "char *strerror(int " errnum );
47 .BI "const char *strerrorname_np(int " errnum );
48 .BI "const char *strerrordesc_np(int " errnum );
50 .BI "int strerror_r(int " errnum ", char *" buf ", size_t " buflen );
53 .BI "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen );
56 .BI "char *strerror_l(int " errnum ", locale_t " locale );
60 Feature Test Macro Requirements for glibc (see
61 .BR feature_test_macros (7)):
64 .BR strerrorname_np (),
65 .BR strerrordesc_np ():
72 The XSI-compliant version is provided if:
73 (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
74 Otherwise, the GNU-specific version is provided.
79 function returns a pointer to a string that describes the error
80 code passed in the argument
84 part of the current locale to select the appropriate language.
89 the returned description will be "Invalid argument".)
90 This string must not be modified by the application, but may be
91 modified by a subsequent call to
95 No other library function, including
97 will modify this string.
102 .BR strerrordesc_np ()
103 function returns a pointer to a string that describes the error
104 code passed in the argument
106 with the difference that the returned string is not translated
107 according to the current locale.
110 .BR strerrorname_np ()
111 function returns a pointer to a string containing the name of the error
112 code passed in the argument
116 as an argument, this function returns a pointer to the string "EPERM".
121 function is similar to
125 This function is available in two versions:
126 an XSI-compliant version specified in POSIX.1-2001
127 (available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13),
128 and a GNU-specific version (available since glibc 2.0).
129 The XSI-compliant version is provided with the feature test macros
130 settings shown in the SYNOPSIS;
131 otherwise the GNU-specific version is provided.
132 If no feature test macros are explicitly defined,
133 then (since glibc 2.4)
135 is defined by default with the value
136 200112L, so that the XSI-compliant version of
138 is provided by default.
142 is preferred for portable applications.
143 It returns the error string in the user-supplied buffer
150 returns a pointer to a string containing the error message.
151 This may be either a pointer to a string that the function stores in
153 or a pointer to some (immutable) static string
157 If the function stores a string in
161 bytes are stored (the string may be truncated if
166 The string always includes a terminating null byte (\(aq\e0\(aq).
174 to a locale-dependent error message in the locale specified by
180 is the special locale object
182 or is not a valid locale object handle.
190 the appropriate error description string,
191 or an "Unknown error nnn" message if the error number is unknown.
194 .BR strerrorname_np ()
196 .BR strerrordesc_np ()
197 return the appropriate error description string.
200 is an invalid error number, these functions return NULL.
204 function returns 0 on success.
206 a (positive) error number is returned (since glibc 2.13),
207 or \-1 is returned and
209 is set to indicate the error (glibc versions before 2.13).
211 POSIX.1-2001 and POSIX.1-2008 require that a successful call to
217 unchanged, and note that,
218 since no function return value is reserved to indicate an error,
219 an application that wishes to check for errors should initialize
221 to zero before the call,
230 is not a valid error number.
233 Insufficient storage was supplied to contain the error description string.
237 function first appeared in glibc 2.6.
240 .BR strerrorname_np ()
242 .BR strerrordesc_np ()
243 functions first appeared in glibc 2.32.
245 For an explanation of the terms used in this section, see
253 Interface Attribute Value
257 MT-Unsafe race:strerror
260 .BR strerrorname_np (),
261 .BR strerrordesc_np ()
262 T} Thread safety MT-Safe
266 T} Thread safety MT-Safe
273 is specified by POSIX.1-2001, POSIX.1-2008, C89, and C99.
275 is specified by POSIX.1-2001 and POSIX.1-2008.
276 .\" FIXME . for later review when Issue 8 is one day released...
277 .\" A future POSIX.1 may remove strerror_r()
278 .\" http://austingroupbugs.net/tag_view_page.php?tag_id=8
279 .\" http://austingroupbugs.net/view.php?id=508
282 is specified in POSIX.1-2008.
284 The GNU-specific functions
286 .BR strerrorname_np (),
288 .BR strerrordesc_np ()
289 are nonstandard extensions.
295 if the call encounters an error, but does not specify what
296 value should be returned as the function result in the event of an error.
298 .\" e.g., Solaris 8, HP-UX 11
300 returns NULL if the error number is unknown.
302 .\" e.g., FreeBSD 5.4, Tru64 5.1B
304 returns a string something like "Error nnn occurred" and sets
308 if the error number is unknown.
309 C99 and POSIX.1-2008 require the return value to be non-NULL.
311 The GNU C Library uses a buffer of 1024 characters for
313 This buffer size therefore should be sufficient to avoid an
318 .BR strerrorname_np ()
320 .BR strerrordesc_np ()
321 are thread-safe and async-signal-safe.