OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[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  2009-03-30 "" "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 \fIerrnum\fP, possibly using the
70 .B LC_MESSAGES
71 part of the current locale to select the appropriate language.
72 This string must not be modified by the application, but may be
73 modified by a subsequent call to
74 .BR perror (3)
75 or
76 .BR strerror ().
77 No library function will modify this string.
78
79 The
80 .BR strerror_r ()
81 function is similar to
82 .BR strerror (),
83 but is
84 thread safe.
85 This function is available in two versions:
86 an XSI-compliant version specified in POSIX.1-2001
87 (available since glibc 2.3.4),
88 and a GNU-specific version (available since glibc 2.0).
89 The XSI-compliant version is provided with the feature test macros
90 settings shown in the SYNOPSIS;
91 otherwise the GNU-specific version is provided.
92 If no feature test macros are explicitly defined,
93 then (since glibc 2.4)
94 .B _POSIX_SOURCE
95 is defined by default with the value
96 200112L, so that the XSI-compliant version of
97 .BR strerror_r ()
98 is provided by default.
99
100 The XSI-compliant
101 .BR strerror_r ()
102 is preferred for portable applications.
103 It returns the error string in the user-supplied buffer
104 .I buf
105 of length
106 .IR buflen .
107
108 The GNU-specific
109 .BR strerror_r ()
110 returns a pointer to a string containing the error message.
111 This may be either a pointer to a string that the function stores in
112 .IR buf ,
113 or a pointer to some (immutable) static string
114 (in which case
115 .I buf
116 is unused).
117 If the function stores a string in
118 .IR buf ,
119 then at most
120 .I buflen
121 bytes are stored (the string may be truncated if
122 .I buflen
123 is too small) and the string always includes a terminating null byte.
124 .SH "RETURN VALUE"
125 The
126 .BR strerror ()
127 and the GNU-specific
128 .BR strerror_r ()
129 functions return
130 the appropriate error description string,
131 or an "Unknown error nnn" message if the error number is unknown.
132
133 The XSI-compliant
134 .BR strerror_r ()
135 function returns 0 on success;
136 on error, \-1 is returned and
137 .I errno
138 is set to indicate the error.
139 .SH ERRORS
140 .TP
141 .B EINVAL
142 The value of
143 .I errnum
144 is not a valid error number.
145 .TP
146 .B ERANGE
147 Insufficient storage was supplied to contain the error description string.
148 .SH "CONFORMING TO"
149 .BR strerror ()
150 is specified by POSIX.1-2001, C89, C99.
151 .BR strerror_r ()
152 is specified by POSIX.1-2001.
153
154 The GNU-specific
155 .BR strerror_r ()
156 function is a nonstandard extension.
157
158 POSIX.1-2001 permits
159 .BR strerror ()
160 to set
161 .I errno
162 if the call encounters an error, but does not specify what
163 value should be returned as the function result in the event of an error.
164 On some systems,
165 .\" e.g., Solaris 8, HP-UX 11
166 .BR strerror ()
167 returns NULL if the error number is unknown.
168 On other systems,
169 .\" e.g., FreeBSD 5.4, Tru64 5.1B
170 .BR strerror ()
171 returns a string something like "Error nnn occurred" and sets
172 .I errno
173 to
174 .B EINVAL
175 if the error number is unknown.
176 .SH "SEE ALSO"
177 .BR err (3),
178 .BR errno (3),
179 .BR error (3),
180 .BR perror (3),
181 .BR strsignal (3)