1STRERROR(3) Linux Programmer's Manual STRERROR(3)
2
3
4
6 strerror, strerror_r - return string describing error number
7
9 #include <string.h>
10
11 char *strerror(int errnum);
12
13 int strerror_r(int errnum, char *buf, size_t buflen);
14 /* XSI-compliant */
15
16 char *strerror_r(int errnum, char *buf, size_t buflen);
17 /* GNU-specific */
18
19 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21 The XSI-compliant version of strerror_r() is provided if:
22 (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
23 Otherwise, the GNU-specific version is provided.
24
26 The strerror() function returns a pointer to a string that describes
27 the error code passed in the argument errnum, possibly using the
28 LC_MESSAGES part of the current locale to select the appropriate lan‐
29 guage. (For example, if errnum is EINVAL, the returned description
30 will "Invalid argument".) This string must not be modified by the
31 application, but may be modified by a subsequent call to strerror().
32 No library function, including perror(3), will modify this string.
33
34 The strerror_r() function is similar to strerror(), but is thread safe.
35 This function is available in two versions: an XSI-compliant version
36 specified in POSIX.1-2001 (available since glibc 2.3.4, but not POSIX-
37 compliant until glibc 2.13), and a GNU-specific version (available
38 since glibc 2.0). The XSI-compliant version is provided with the fea‐
39 ture test macros settings shown in the SYNOPSIS; otherwise the GNU-spe‐
40 cific version is provided. If no feature test macros are explicitly
41 defined, then (since glibc 2.4) _POSIX_SOURCE is defined by default
42 with the value 200112L, so that the XSI-compliant version of str‐
43 error_r() is provided by default.
44
45 The XSI-compliant strerror_r() is preferred for portable applications.
46 It returns the error string in the user-supplied buffer buf of length
47 buflen.
48
49 The GNU-specific strerror_r() returns a pointer to a string containing
50 the error message. This may be either a pointer to a string that the
51 function stores in buf, or a pointer to some (immutable) static string
52 (in which case buf is unused). If the function stores a string in buf,
53 then at most buflen bytes are stored (the string may be truncated if
54 buflen is too small and errnum is unknown). The string always includes
55 a terminating null byte ('\0').
56
58 The strerror() and the GNU-specific strerror_r() functions return the
59 appropriate error description string, or an "Unknown error nnn" message
60 if the error number is unknown.
61
62 POSIX.1-2001 and POSIX.1-2008 require that a successful call to str‐
63 error() shall leave errno unchanged, and note that, since no function
64 return value is reserved to indicate an error, an application that
65 wishes to check for errors should initialize errno to zero before the
66 call, and then check errno after the call.
67
68 The XSI-compliant strerror_r() function returns 0 on success. On
69 error, a (positive) error number is returned (since glibc 2.13), or -1
70 is returned and errno is set to indicate the error (glibc versions
71 before 2.13).
72
74 EINVAL The value of errnum is not a valid error number.
75
76 ERANGE Insufficient storage was supplied to contain the error descrip‐
77 tion string.
78
80 Multithreading (see pthreads(7))
81 The strerror() function is not thread-safe.
82
83 The strerror_r() function is thread-safe.
84
86 strerror() is specified by POSIX.1-2001, C89, C99. strerror_r() is
87 specified by POSIX.1-2001.
88
89 The GNU-specific strerror_r() function is a nonstandard extension.
90
91 POSIX.1-2001 permits strerror() to set errno if the call encounters an
92 error, but does not specify what value should be returned as the func‐
93 tion result in the event of an error. On some systems, strerror()
94 returns NULL if the error number is unknown. On other systems, str‐
95 error() returns a string something like "Error nnn occurred" and sets
96 errno to EINVAL if the error number is unknown. C99 and POSIX.1-2008
97 require the return value to be non-NULL.
98
100 err(3), errno(3), error(3), perror(3), strsignal(3)
101
103 This page is part of release 3.53 of the Linux man-pages project. A
104 description of the project, and information about reporting bugs, can
105 be found at http://www.kernel.org/doc/man-pages/.
106
107
108
109 2013-06-21 STRERROR(3)