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 char *strerror_r(int errnum, char *buf, size_t buflen);
14 /* GNU-specific strerror_r() */
15
16 #define _XOPEN_SOURCE 600
17 #include <string.h>
18
19 int strerror_r(int errnum, char *buf, size_t buflen);
20 /* XSI-compliant strerror_r() */
21
23 The strerror() function returns a string describing the error code
24 passed in the argument errnum, possibly using the LC_MESSAGES part of
25 the current locale to select the appropriate language. This string
26 must not be modified by the application, but may be modified by a sub‐
27 sequent call to perror() or strerror(). No library function will mod‐
28 ify this string.
29
30 The strerror_r() function is similar to strerror(), but is thread safe.
31 This function is available in two versions: an XSI-compliant version
32 specified in POSIX.1-2001, and a GNU-specific version (available since
33 glibc 2.0). If _XOPEN_SOURCE is defined with the value 600, then the
34 XSI-compliant version is provided, otherwise the GNU-specific version
35 is provided.
36
37 The XSI-compliant strerror_r() is preferred for portable applications.
38 It returns the error string in the user-supplied buffer buf of length
39 buflen.
40
41 The GNU-specific strerror_r() returns a pointer to a string containing
42 the error message. This may be either a pointer to a string that the
43 function stores in buf, or a pointer to some (immutable) static string
44 (in which case buf is unused). If the function stores a string in buf,
45 then at most buflen bytes are stored (the string may be truncated if
46 buflen is too small) and the string always includes a terminating null
47 byte.
48
49
51 The strerror() and strerror_r() functions return the appropriate error
52 description string, or an "Unknown error nnn" message if the error num‐
53 ber is unknown.
54
55 The XSI-compliant strerror_r() function returns 0 on success; on error,
56 -1 is returned and errno is set to indicate the error.
57
58
60 EINVAL The value of errnum is not a valid error number.
61
62 ERANGE Insufficient storage was supplied to contain the error descrip‐
63 tion string.
64
65
67 strerror() is specified by POSIX.1-2001, C89, C99. strerror_r() is
68 specified by POSIX.1-2001.
69
70 The GNU-specific strerror_r() function is a non-standard extension.
71
72 POSIX.1-2001 permits strerror() to set errno if the call encounters an
73 error, but does not specify what value should be returned as the func‐
74 tion result in the event of an error. On some systems, strerror()
75 returns NULL if the error number is unknown. On other systems, str‐
76 error() returns a string something like "Error nnn occurred" and sets
77 errno to EINVAL if the error number is unknown.
78
79
81 err(3), errno(3), error(3), perror(3), strsignal(3), fea‐
82 ture_test_macros(7)
83
84
85
86 2005-12-13 STRERROR(3)