1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
'\" et
.TH STRERROR "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.SH NAME
strerror,
strerror_l,
strerror_r
\(em get error message string
.SH SYNOPSIS
.LP
.nf
#include <string.h>
.P
char *strerror(int \fIerrnum\fR);
char *strerror_l(int \fIerrnum\fR, locale_t \fIlocale\fR);
int strerror_r(int \fIerrnum\fR, char *\fIstrerrbuf\fR, size_t \fIbuflen\fR);
.fi
.SH DESCRIPTION
For
\fIstrerror\fR():
The functionality described on this reference page is aligned with the
ISO\ C standard. Any conflict between the requirements described here and the
ISO\ C standard is unintentional. This volume of POSIX.1\(hy2008 defers to the ISO\ C standard.
.P
The
\fIstrerror\fR()
function shall map the error number in
.IR errnum
to a locale-dependent error message string and shall return a pointer
to it. Typically, the values for
.IR errnum
come from
.IR errno ,
but
\fIstrerror\fR()
shall map any value of type
.BR int
to a message.
.P
The application shall not modify the string returned.
The returned string pointer might be invalidated or
the string content might be overwritten by a subsequent call to
\fIstrerror\fR(),
or by a subsequent call to
\fIstrerror_l\fR()
in the same thread.
.P
The string may be overwritten by a subsequent call to
\fIstrerror_l\fR()
in the same thread.
.P
The contents of the error message strings returned by
\fIstrerror\fR()
should be determined by the setting of the
.IR LC_MESSAGES
category in the current locale.
.P
The implementation shall behave as if no function defined in this volume of POSIX.1\(hy2008
calls
\fIstrerror\fR().
.P
The
\fIstrerror\fR()
and
\fIstrerror_l\fR()
functions shall not change the setting of
.IR errno
if successful.
.P
Since no return value is reserved to indicate an error of
\fIstrerror\fR(),
an application wishing to check for error situations should set
.IR errno
to 0, then call
\fIstrerror\fR(),
then check
.IR errno .
Similarly, since
\fIstrerror_l\fR()
is required to return a string for some errors, an application wishing
to check for all error situations should set
.IR errno
to 0, then call
\fIstrerror_l\fR(),
then check
.IR errno .
.P
The
\fIstrerror\fR()
function need not be thread-safe.
.P
The
\fIstrerror_l\fR()
function shall map the error number in
.IR errnum
to a locale-dependent error message string in the locale represented by
.IR locale
and shall return a pointer to it.
.P
The
\fIstrerror_r\fR()
function shall map the error number in
.IR errnum
to a locale-dependent error message string and shall return the string
in the buffer pointed to by
.IR strerrbuf ,
with length
.IR buflen .
.P
If the value of
.IR errnum
is a valid error number, the message string shall indicate what error
occurred; if the value of
.IR errnum
is zero, the message string shall either be an empty string or
indicate that no error occurred; otherwise, if these functions complete
successfully, the message string shall indicate that an unknown error
occurred.
.P
The behavior is undefined if the
.IR locale
argument to
\fIstrerror_l\fR()
is the special locale object LC_GLOBAL_LOCALE or is not a valid locale
object handle.
.SH "RETURN VALUE"
Upon completion, whether successful or not,
\fIstrerror\fR()
shall return a pointer to the generated message string.
On error
.IR errno
may be set, but no return value is reserved to indicate an error.
.P
Upon successful completion,
\fIstrerror_l\fR()
shall return a pointer to the generated message string. If
.IR errnum
is not a valid error number,
.IR errno
may be set to
.BR [EINVAL] ,
but a pointer to a message string shall still be returned. If any other
error occurs,
.IR errno
shall be set to indicate the error and a null pointer shall be
returned.
.P
Upon successful completion,
\fIstrerror_r\fR()
shall return 0. Otherwise, an error number shall be returned to
indicate the error.
.SH ERRORS
These functions may fail if:
.TP
.BR EINVAL
The value of
.IR errnum
is neither a valid error number nor zero.
.P
The
\fIstrerror_r\fR()
function may fail if:
.TP
.BR ERANGE
Insufficient storage was supplied via
.IR strerrbuf
and
.IR buflen
to contain the generated message string.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
None.
.SH "APPLICATION USAGE"
Historically in some implementations, calls to
\fIperror\fR()
would overwrite the string that the pointer returned by
\fIstrerror\fR()
points to. Such implementations did not conform to the ISO\ C standard; however,
application developers should be aware of this behavior if they wish
their applications to be portable to such implementations.
.SH RATIONALE
The
\fIstrerror_l\fR()
function is required to be thread-safe, thereby eliminating the
need for an equivalent to the
\fIstrerror_r\fR()
function.
.P
Earlier versions of this standard did not explicitly require that the
error message strings returned by
\fIstrerror\fR()
and
\fIstrerror_r\fR()
provide any information about the error. This version of the standard
requires a meaningful message for any successful completion.
.P
Since no return value is reserved to indicate a
\fIstrerror\fR()
error, but all calls (whether successful or not) must return a pointer
to a message string, on error
\fIstrerror\fR()
can return a pointer to an empty string or a pointer to a meaningful
string that can be printed.
.P
Note that the
.BR [EINVAL]
error condition is a may fail error. If an invalid error number is
supplied as the value of
.IR errnum ,
applications should be prepared to handle any of the following:
.IP " 1." 4
Error (with no meaningful message):
.IR errno
is set to
.BR [EINVAL] ,
the return value is a pointer to an empty string.
.IP " 2." 4
Successful completion:
.IR errno
is unchanged and the return value points to a string like
.BR \(dqunknown error\(dq
or
.BR \(dqerror number xxx\(dq
(where
.IR xxx
is the value of
.IR errnum ).
.IP " 3." 4
Combination of #1 and #2:
.IR errno
is set to
.BR [EINVAL]
and the return value points to a string like
.BR \(dqunknown error\(dq
or
.BR \(dqerror number xxx\(dq
(where
.IR xxx
is the value of
.IR errnum ).
Since applications frequently use the return value of
\fIstrerror\fR()
as an argument to functions like
\fIfprintf\fR()
(without checking the return value) and since applications have no way
to parse an error message string to determine whether
.IR errnum
represents a valid error number, implementations are encouraged to
implement #3. Similarly, implementations are encouraged to have
\fIstrerror_r\fR()
return
.BR [EINVAL]
and put a string like
.BR \(dqunknown error\(dq
or
.BR \(dqerror number xxx\(dq
in the buffer pointed to by
.IR strerrbuf
when the value of
.IR errnum
is not a valid error number.
.P
Some applications rely on being able to set
.IR errno
to 0 before calling a function with no reserved value to indicate an
error, then call
.IR strerror ( errno )
afterwards to detect whether an error occurred (because
.IR errno
changed) or to indicate success (because
.IR errno
remained zero). This usage pattern requires that
.IR strerror (0)
succeed with useful results. Previous versions of the standard did not
specify the behavior when
.IR errnum
is zero.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIperror\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2008,
.IR "\fB<string.h>\fP"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.unix.org/online.html .
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|