OSDN Git Service

(split) LDP: Update original to LDP v3.40.
[linuxjm/LDP_man-pages.git] / original / man3 / strerror.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2005, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" References consulted:
25 .\"     Linux libc source code
26 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\"     386BSD man pages
28 .\" Modified Sat Jul 24 18:05:30 1993 by Rik Faith <faith@cs.unc.edu>
29 .\" Modified Fri Feb 16 14:25:17 1996 by Andries Brouwer <aeb@cwi.nl>
30 .\" Modified Sun Jul 21 20:55:44 1996 by Andries Brouwer <aeb@cwi.nl>
31 .\" Modified Mon Oct 15 21:16:25 2001 by John Levon <moz@compsoc.man.ac.uk>
32 .\" Modified Tue Oct 16 00:04:43 2001 by Andries Brouwer <aeb@cwi.nl>
33 .\" Modified Fri Jun 20 03:04:30 2003 by Andries Brouwer <aeb@cwi.nl>
34 .\" 2005-12-13, mtk, Substantial rewrite of strerror_r() description
35 .\"         Addition of extra material on portability and standards.
36 .\"
37 .TH STRERROR 3  2012-04-22 "" "Linux Programmer's Manual"
38 .SH NAME
39 strerror, strerror_r \- return string describing error number
40 .SH SYNOPSIS
41 .nf
42 .B #include <string.h>
43 .sp
44 .BI "char *strerror(int " errnum );
45 .sp
46 .BI "int strerror_r(int " errnum ", char *" buf ", size_t " buflen );
47             /* XSI-compliant */
48 .sp
49 .BI "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen );
50             /* GNU-specific */
51 .fi
52 .sp
53 .in -4n
54 Feature Test Macro Requirements for glibc (see
55 .BR feature_test_macros (7)):
56 .in
57 .sp
58 The XSI-compliant version of
59 .BR strerror_r ()
60 is provided if:
61 .br
62 (_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600) && !\ _GNU_SOURCE
63 .br
64 Otherwise, the GNU-specific version is provided.
65 .SH DESCRIPTION
66 The
67 .BR strerror ()
68 function returns a pointer to a string that describes the error
69 code passed in the argument
70 .IR errnum ,
71 possibly using the
72 .B LC_MESSAGES
73 part of the current locale to select the appropriate language.
74 (For example, if
75 .I errnum
76 is
77 .BR EINVAL ,
78 the returned description will "Invalid argument".)
79 This string must not be modified by the application, but may be
80 modified by a subsequent call to
81 .BR strerror ().
82 No library function, including
83 .BR perror (3),
84 will modify this string.
85
86 The
87 .BR strerror_r ()
88 function is similar to
89 .BR strerror (),
90 but is
91 thread safe.
92 This function is available in two versions:
93 an XSI-compliant version specified in POSIX.1-2001
94 (available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13),
95 and a GNU-specific version (available since glibc 2.0).
96 The XSI-compliant version is provided with the feature test macros
97 settings shown in the SYNOPSIS;
98 otherwise the GNU-specific version is provided.
99 If no feature test macros are explicitly defined,
100 then (since glibc 2.4)
101 .B _POSIX_SOURCE
102 is defined by default with the value
103 200112L, so that the XSI-compliant version of
104 .BR strerror_r ()
105 is provided by default.
106
107 The XSI-compliant
108 .BR strerror_r ()
109 is preferred for portable applications.
110 It returns the error string in the user-supplied buffer
111 .I buf
112 of length
113 .IR buflen .
114
115 The GNU-specific
116 .BR strerror_r ()
117 returns a pointer to a string containing the error message.
118 This may be either a pointer to a string that the function stores in
119 .IR buf ,
120 or a pointer to some (immutable) static string
121 (in which case
122 .I buf
123 is unused).
124 If the function stores a string in
125 .IR buf ,
126 then at most
127 .I buflen
128 bytes are stored (the string may be truncated if
129 .I buflen
130 is too small and
131 .I errnum
132 is unknown).
133 The string always includes a terminating null byte.
134 .SH "RETURN VALUE"
135 The
136 .BR strerror ()
137 and the GNU-specific
138 .BR strerror_r ()
139 functions return
140 the appropriate error description string,
141 or an "Unknown error nnn" message if the error number is unknown.
142
143 POSIX.1-2001 and POSIX.1-2008 require that a successful call to
144 .BR strerror (3)
145 shall leave
146 .I errno
147 unchanged, and note that,
148 since no function return value is reserved to indicate an error,
149 an application that wishes to check for errors should initialize
150 .I errno
151 to zero before the call,
152 and then check
153 .I errno
154 after the call.
155
156 The XSI-compliant
157 .BR strerror_r ()
158 function returns 0 on success.
159 On error,
160 a (positive) error number is returned (since glibc 2.13),
161 or \-1 is returned and
162 .I errno
163 is set to indicate the error (glibc versions before 2.13).
164 .SH ERRORS
165 .TP
166 .B EINVAL
167 The value of
168 .I errnum
169 is not a valid error number.
170 .TP
171 .B ERANGE
172 Insufficient storage was supplied to contain the error description string.
173 .SH "CONFORMING TO"
174 .BR strerror ()
175 is specified by POSIX.1-2001, C89, C99.
176 .BR strerror_r ()
177 is specified by POSIX.1-2001.
178
179 The GNU-specific
180 .BR strerror_r ()
181 function is a nonstandard extension.
182
183 POSIX.1-2001 permits
184 .BR strerror ()
185 to set
186 .I errno
187 if the call encounters an error, but does not specify what
188 value should be returned as the function result in the event of an error.
189 On some systems,
190 .\" e.g., Solaris 8, HP-UX 11
191 .BR strerror ()
192 returns NULL if the error number is unknown.
193 On other systems,
194 .\" e.g., FreeBSD 5.4, Tru64 5.1B
195 .BR strerror ()
196 returns a string something like "Error nnn occurred" and sets
197 .I errno
198 to
199 .B EINVAL
200 if the error number is unknown.
201 C99 and POSIX.1-2008 require the return value to be non-NULL.
202 .SH "SEE ALSO"
203 .BR err (3),
204 .BR errno (3),
205 .BR error (3),
206 .BR perror (3),
207 .BR strsignal (3)