1STRERROR(3)                Linux Programmer's Manual               STRERROR(3)
2
3
4

NAME

6       strerror,  strerrorname_np,  strerrordesc_np,  strerror_r, strerror_l -
7       return string describing error number
8

SYNOPSIS

10       #include <string.h>
11
12       char *strerror(int errnum);
13       const char *strerrorname_np(int errnum);
14       const char *strerrordesc_np(int errnum);
15
16       int strerror_r(int errnum, char *buf, size_t buflen);
17                      /* XSI-compliant */
18
19       char *strerror_r(int errnum, char *buf, size_t buflen);
20                      /* GNU-specific */
21
22       char *strerror_l(int errnum, locale_t locale);
23
24   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
25
26       strerrorname_np(), strerrordesc_np():
27           _GNU_SOURCE
28
29       strerror_r():
30           The XSI-compliant version is provided if:
31               (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
32           Otherwise, the GNU-specific version is provided.
33

DESCRIPTION

35       The strerror() function returns a pointer to a  string  that  describes
36       the  error  code  passed  in  the  argument  errnum, possibly using the
37       LC_MESSAGES part of the current locale to select the  appropriate  lan‐
38       guage.   (For  example,  if  errnum is EINVAL, the returned description
39       will be "Invalid argument".)  This string must not be modified  by  the
40       application,  but may be modified by a subsequent call to strerror() or
41       strerror_l().  No other library  function,  including  perror(3),  will
42       modify this string.
43
44       Like  strerror(), the strerrordesc_np() function returns a pointer to a
45       string that describes the error code passed  in  the  argument  errnum,
46       with  the difference that the returned string is not translated accord‐
47       ing to the current locale.
48
49       The strerrorname_np() function returns a pointer to a string containing
50       the name of the error code passed in the argument errnum.  For example,
51       given EPERM as an argument, this function  returns  a  pointer  to  the
52       string "EPERM".
53
54   strerror_r()
55       The strerror_r() function is similar to strerror(), but is thread safe.
56       This function is available in two versions:  an  XSI-compliant  version
57       specified  in POSIX.1-2001 (available since glibc 2.3.4, but not POSIX-
58       compliant until glibc 2.13),  and  a  GNU-specific  version  (available
59       since  glibc 2.0).  The XSI-compliant version is provided with the fea‐
60       ture test macros settings shown in the SYNOPSIS; otherwise the GNU-spe‐
61       cific  version  is  provided.  If no feature test macros are explicitly
62       defined, then (since glibc 2.4) _POSIX_C_SOURCE is defined  by  default
63       with  the  value  200112L,  so  that  the XSI-compliant version of str‐
64       error_r() is provided by default.
65
66       The XSI-compliant strerror_r() is preferred for portable  applications.
67       It  returns  the error string in the user-supplied buffer buf of length
68       buflen.
69
70       The GNU-specific strerror_r() returns a pointer to a string  containing
71       the  error  message.  This may be either a pointer to a string that the
72       function stores in buf, or a pointer to some (immutable) static  string
73       (in which case buf is unused).  If the function stores a string in buf,
74       then at most buflen bytes are stored (the string may  be  truncated  if
75       buflen is too small and errnum is unknown).  The string always includes
76       a terminating null byte ('\0').
77
78   strerror_l()
79       strerror_l() is like strerror(), but maps errnum to a  locale-dependent
80       error  message in the locale specified by locale.  The behavior of str‐
81       error_l()  is  undefined  if  locale  is  the  special  locale   object
82       LC_GLOBAL_LOCALE or is not a valid locale object handle.
83

RETURN VALUE

85       The  strerror(),  strerror_l(), and the GNU-specific strerror_r() func‐
86       tions return the appropriate error description string, or  an  "Unknown
87       error nnn" message if the error number is unknown.
88
89       On  success,  strerrorname_np() and strerrordesc_np() return the appro‐
90       priate error description string.  If errnum is an invalid error number,
91       these functions return NULL.
92
93       The  XSI-compliant  strerror_r() function returns 0 on success.  On er‐
94       ror, a (positive) error number is returned (since glibc 2.13), or -1 is
95       returned  and errno is set to indicate the error (glibc versions before
96       2.13).
97
98       POSIX.1-2001 and POSIX.1-2008 require that a successful  call  to  str‐
99       error()  or  strerror_l()  shall  leave errno unchanged, and note that,
100       since no function return value is reserved to indicate an error, an ap‐
101       plication  that  wishes  to check for errors should initialize errno to
102       zero before the call, and then check errno after the call.
103

ERRORS

105       EINVAL The value of errnum is not a valid error number.
106
107       ERANGE Insufficient storage was supplied to contain the error  descrip‐
108              tion string.
109

VERSIONS

111       The strerror_l() function first appeared in glibc 2.6.
112
113       The strerrorname_np() and strerrordesc_np() functions first appeared in
114       glibc 2.32.
115

ATTRIBUTES

117       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
118       tributes(7).
119
120       ┌───────────────────┬───────────────┬──────────────────────────────────┐
121Interface          Attribute     Value                            
122       ├───────────────────┼───────────────┼──────────────────────────────────┤
123strerror()         │ Thread safety │ MT-Unsafe race:strerror          │
124       ├───────────────────┼───────────────┼──────────────────────────────────┤
125strerrorname_np(), │ Thread safety │ MT-Safe                          │
126strerrordesc_np()  │               │                                  │
127       ├───────────────────┼───────────────┼──────────────────────────────────┤
128strerror_r(),      │ Thread safety │ MT-Safe                          │
129strerror_l()       │               │                                  │
130       └───────────────────┴───────────────┴──────────────────────────────────┘
131

CONFORMING TO

133       strerror()  is  specified  by POSIX.1-2001, POSIX.1-2008, C89, and C99.
134       strerror_r() is specified by POSIX.1-2001 and POSIX.1-2008.
135
136       strerror_l() is specified in POSIX.1-2008.
137
138       The GNU-specific functions strerror_r(),  strerrorname_np(),  and  str‐
139       errordesc_np() are nonstandard extensions.
140
141       POSIX.1-2001  permits strerror() to set errno if the call encounters an
142       error, but does not specify what value should be returned as the  func‐
143       tion  result in the event of an error.  On some systems, strerror() re‐
144       turns NULL if the error number is  unknown.   On  other  systems,  str‐
145       error()  returns  a string something like "Error nnn occurred" and sets
146       errno to EINVAL if the error number is unknown.  C99  and  POSIX.1-2008
147       require the return value to be non-NULL.
148

NOTES

150       The  GNU  C  Library  uses  a buffer of 1024 characters for strerror().
151       This buffer size therefore should be sufficient to avoid an ERANGE  er‐
152       ror when calling strerror_r().
153
154       strerrorname_np()  and strerrordesc_np() are thread-safe and async-sig‐
155       nal-safe.
156

SEE ALSO

158       err(3), errno(3), error(3), perror(3), strsignal(3), locale(7)
159

COLOPHON

161       This page is part of release 5.12 of the Linux  man-pages  project.   A
162       description  of  the project, information about reporting bugs, and the
163       latest    version    of    this    page,    can     be     found     at
164       https://www.kernel.org/doc/man-pages/.
165
166
167
168                                  2021-03-22                       STRERROR(3)
Impressum