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

NAME

6       strerror, strerror_r - return string describing error number
7

SYNOPSIS

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

DESCRIPTION

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.  This string must not be modified by the application, but may be
30       modified  by  a subsequent call to perror(3) or strerror().  No library
31       function will modify this string.
32
33       The strerror_r() function is similar to strerror(), but is thread safe.
34       This  function  is  available in two versions: an XSI-compliant version
35       specified in POSIX.1-2001 (available since glibc 2.3.4), and a GNU-spe‐
36       cific  version  (available since glibc 2.0).  The XSI-compliant version
37       is provided with the feature test macros settings shown in  the  SYNOP‐
38       SIS;  otherwise  the  GNU-specific  version is provided.  If no feature
39       test  macros  are  explicitly   defined,   then   (since   glibc   2.4)
40       _POSIX_SOURCE is defined by default with the value 200112L, so that the
41       XSI-compliant version of strerror_r() is provided by default.
42
43       The XSI-compliant strerror_r() is preferred for portable  applications.
44       It  returns  the error string in the user-supplied buffer buf of length
45       buflen.
46
47       The GNU-specific strerror_r() returns a pointer to a string  containing
48       the  error  message.  This may be either a pointer to a string that the
49       function stores in buf, or a pointer to some (immutable) static  string
50       (in which case buf is unused).  If the function stores a string in buf,
51       then at most buflen bytes are stored (the string may  be  truncated  if
52       buflen  is too small) and the string always includes a terminating null
53       byte.
54

RETURN VALUE

56       The strerror() and the GNU-specific strerror_r() functions  return  the
57       appropriate error description string, or an "Unknown error nnn" message
58       if the error number is unknown.
59
60       The XSI-compliant strerror_r() function returns 0 on success; on error,
61       -1 is returned and errno is set to indicate the error.
62

ERRORS

64       EINVAL The value of errnum is not a valid error number.
65
66       ERANGE Insufficient  storage was supplied to contain the error descrip‐
67              tion string.
68

CONFORMING TO

70       strerror() is specified by POSIX.1-2001,  C89,  C99.   strerror_r()  is
71       specified by POSIX.1-2001.
72
73       The GNU-specific strerror_r() function is a non-standard extension.
74
75       POSIX.1-2001  permits strerror() to set errno if the call encounters an
76       error, but does not specify what value should be returned as the  func‐
77       tion  result  in  the  event  of an error.  On some systems, strerror()
78       returns NULL if the error number is unknown.  On  other  systems,  str‐
79       error()  returns  a string something like "Error nnn occurred" and sets
80       errno to EINVAL if the error number is unknown.
81

SEE ALSO

83       err(3), errno(3), error(3), perror(3), strsignal(3)
84

COLOPHON

86       This page is part of release 3.22 of the Linux  man-pages  project.   A
87       description  of  the project, and information about reporting bugs, can
88       be found at http://www.kernel.org/doc/man-pages/.
89
90
91
92                                  2009-03-30                       STRERROR(3)
Impressum