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       strerror_r():
29           The XSI-compliant version is provided if:
30           (_POSIX_C_SOURCE >= 200112L) && !  _GNU_SOURCE
31           Otherwise, the GNU-specific version is provided.
32

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

VERSIONS

110       The strerror_l() function first appeared in glibc 2.6.
111

ATTRIBUTES

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

CONFORMING TO

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

NOTES

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

SEE ALSO

153       err(3), errno(3), error(3), perror(3), strsignal(3), locale(7)
154

COLOPHON

156       This page is part of release 5.10 of the Linux  man-pages  project.   A
157       description  of  the project, information about reporting bugs, and the
158       latest    version    of    this    page,    can     be     found     at
159       https://www.kernel.org/doc/man-pages/.
160
161
162
163                                  2020-11-01                       STRERROR(3)
Impressum