OSDN Git Service

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