]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strerror.3
ffix
[thirdparty/man-pages.git] / man3 / strerror.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2005, Michael Kerrisk <mtk-manpages@gmx.net>
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 2005-12-13 "" "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 "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen );
47 /* GNU-specific strerror_r() */
48 .sp
49 .B #define _XOPEN_SOURCE 600
50 .B #include <string.h>
51 .sp
52 .BI "int strerror_r(int " errnum ", char *" buf ", size_t " buflen );
53 /* XSI-compliant strerror_r() */
54 .fi
55 .SH DESCRIPTION
56 The
57 .BR strerror ()
58 function returns a string describing the error
59 code passed in the argument \fIerrnum\fP, possibly using the LC_MESSAGES
60 part of the current locale to select the appropriate language.
61 This string must not be modified by the application, but may be
62 modified by a subsequent call to
63 .BR perror (3)
64 or
65 .BR strerror ().
66 No library function will modify this string.
67
68 The
69 .BR strerror_r ()
70 function is similar to
71 .BR strerror (),
72 but is
73 thread safe.
74 This function is available in two versions:
75 an XSI-compliant version specified in POSIX.1-2001,
76 and a GNU-specific version (available since glibc 2.0).
77 If
78 .B _XOPEN_SOURCE
79 is defined with the value 600,
80 then the XSI-compliant version is provided,
81 otherwise the GNU-specific version is provided.
82
83 The XSI-compliant
84 .BR strerror_r ()
85 is preferred for portable applications.
86 It returns the error string in the user-supplied buffer
87 .I buf
88 of length
89 .IR buflen .
90
91 The GNU-specific
92 .BR strerror_r ()
93 returns a pointer to a string containing the error message.
94 This may be either a pointer to a string that the function stores in
95 .IR buf ,
96 or a pointer to some (immutable) static string
97 (in which case
98 .I buf
99 is unused).
100 If the function stores a string in
101 .IR buf ,
102 then at most
103 .I buflen
104 bytes are stored (the string may be truncated if
105 .I buflen
106 is too small) and the string always includes a terminating null byte.
107 .SH "RETURN VALUE"
108 The
109 .BR strerror ()
110 and
111 .BR strerror_r ()
112 functions return
113 the appropriate error description string,
114 or an "Unknown error nnn" message if the error number is unknown.
115
116 The XSI-compliant
117 .BR strerror_r ()
118 function returns 0 on success;
119 on error, \-1 is returned and
120 .I errno
121 is set to indicate the error.
122 .SH ERRORS
123 .TP
124 .B EINVAL
125 The value of
126 .I errnum
127 is not a valid error number.
128 .TP
129 .B ERANGE
130 Insufficient storage was supplied to contain the error description string.
131 .SH "CONFORMING TO"
132 .BR strerror ()
133 is specified by POSIX.1-2001, C89, C99.
134 .BR strerror_r ()
135 is specified by POSIX.1-2001.
136
137 The GNU-specific
138 .BR strerror_r ()
139 function is a non-standard extension.
140
141 POSIX.1-2001 permits
142 .BR strerror ()
143 to set
144 .I errno
145 if the call encounters an error, but does not specify what
146 value should be returned as the function result in the event of an error.
147 On some systems,
148 .\" e.g., Solaris 8, HP-UX 11
149 .BR strerror ()
150 returns NULL if the error number is unknown.
151 On other systems,
152 .\" e.g., FreeBSD 5.4, Tru64 5.1B
153 .BR strerror ()
154 returns a string something like "Error nnn occurred" and sets
155 .I errno
156 to
157 .B EINVAL
158 if the error number is unknown.
159 .SH "SEE ALSO"
160 .BR err (3),
161 .BR errno (3),
162 .BR error (3),
163 .BR perror (3),
164 .BR strsignal (3),
165 .BR feature_test_macros (7)