1<html lang="en"> 2<head> 3<title>strerror - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Strings.html#Strings" title="Strings"> 9<link rel="prev" href="strcspn.html#strcspn" title="strcspn"> 10<link rel="next" href="strerror_005fr.html#strerror_005fr" title="strerror_r"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="strerror"></a> 29<p> 30Next: <a rel="next" accesskey="n" href="strerror_005fr.html#strerror_005fr">strerror_r</a>, 31Previous: <a rel="previous" accesskey="p" href="strcspn.html#strcspn">strcspn</a>, 32Up: <a rel="up" accesskey="u" href="Strings.html#Strings">Strings</a> 33<hr> 34</div> 35 36<h3 class="section">5.24 <code>strerror</code>—convert error number to string</h3> 37 38<p><a name="index-strerror-392"></a><strong>Synopsis</strong> 39<pre class="example"> #include <string.h> 40 char *strerror(int <var>errnum</var>); 41 char *_strerror_r(struct _reent <var>ptr</var>, int <var>errnum</var>, 42 int <var>internal</var>, int *<var>error</var>); 43 44</pre> 45 <p><strong>Description</strong><br> 46<code>strerror</code> converts the error number <var>errnum</var> into a 47string. The value of <var>errnum</var> is usually a copy of <code>errno</code>. 48If <code>errnum</code> is not a known error number, the result points to an 49empty string. 50 51 <p>This implementation of <code>strerror</code> prints out the following strings 52for each of the values defined in `<code>errno.h</code>': 53 54 <dl> 55<dt><code>0</code><dd>Success 56 57 <br><dt><code>E2BIG</code><dd>Arg list too long 58 59 <br><dt><code>EACCES</code><dd>Permission denied 60 61 <br><dt><code>EADDRINUSE</code><dd>Address already in use 62 63 <br><dt><code>EADV</code><dd>Advertise error 64 65 <br><dt><code>EAFNOSUPPORT</code><dd>Address family not supported by protocol family 66 67 <br><dt><code>EAGAIN</code><dd>No more processes 68 69 <br><dt><code>EALREADY</code><dd>Socket already connected 70 71 <br><dt><code>EBADF</code><dd>Bad file number 72 73 <br><dt><code>EBADMSG</code><dd>Bad message 74 75 <br><dt><code>EBUSY</code><dd>Device or resource busy 76 77 <br><dt><code>ECHILD</code><dd>No children 78 79 <br><dt><code>ECOMM</code><dd>Communication error 80 81 <br><dt><code>ECONNABORTED</code><dd>Software caused connection abort 82 83 <br><dt><code>ECONNREFUSED</code><dd>Connection refused 84 85 <br><dt><code>EDEADLK</code><dd>Deadlock 86 87 <br><dt><code>EDESTADDRREQ</code><dd>Destination address required 88 89 <br><dt><code>EEXIST</code><dd>File exists 90 91 <br><dt><code>EDOM</code><dd>Math argument 92 93 <br><dt><code>EFAULT</code><dd>Bad address 94 95 <br><dt><code>EFBIG</code><dd>File too large 96 97 <br><dt><code>EHOSTDOWN</code><dd>Host is down 98 99 <br><dt><code>EHOSTUNREACH</code><dd>Host is unreachable 100 101 <br><dt><code>EIDRM</code><dd>Identifier removed 102 103 <br><dt><code>EINPROGRESS</code><dd>Connection already in progress 104 105 <br><dt><code>EINTR</code><dd>Interrupted system call 106 107 <br><dt><code>EINVAL</code><dd>Invalid argument 108 109 <br><dt><code>EIO</code><dd>I/O error 110 111 <br><dt><code>EISCONN</code><dd>Socket is already connected 112 113 <br><dt><code>EISDIR</code><dd>Is a directory 114 115 <br><dt><code>ELIBACC</code><dd>Cannot access a needed shared library 116 117 <br><dt><code>ELIBBAD</code><dd>Accessing a corrupted shared library 118 119 <br><dt><code>ELIBEXEC</code><dd>Cannot exec a shared library directly 120 121 <br><dt><code>ELIBMAX</code><dd>Attempting to link in more shared libraries than system limit 122 123 <br><dt><code>ELIBSCN</code><dd><code>.lib</code> section in a.out corrupted 124 125 <br><dt><code>EMFILE</code><dd>Too many open files 126 127 <br><dt><code>EMLINK</code><dd>Too many links 128 129 <br><dt><code>EMSGSIZE</code><dd>Message too long 130 131 <br><dt><code>EMULTIHOP</code><dd>Multihop attempted 132 133 <br><dt><code>ENAMETOOLONG</code><dd>File or path name too long 134 135 <br><dt><code>ENETDOWN</code><dd>Network interface not configured 136 137 <br><dt><code>ENETUNREACH</code><dd>Network is unreachable 138 139 <br><dt><code>ENFILE</code><dd>Too many open files in system 140 141 <br><dt><code>ENODEV</code><dd>No such device 142 143 <br><dt><code>ENOENT</code><dd>No such file or directory 144 145 <br><dt><code>ENOEXEC</code><dd>Exec format error 146 147 <br><dt><code>ENOLCK</code><dd>No lock 148 149 <br><dt><code>ENOLINK</code><dd>Virtual circuit is gone 150 151 <br><dt><code>ENOMEM</code><dd>Not enough space 152 153 <br><dt><code>ENOMSG</code><dd>No message of desired type 154 155 <br><dt><code>ENONET</code><dd>Machine is not on the network 156 157 <br><dt><code>ENOPKG</code><dd>No package 158 159 <br><dt><code>ENOPROTOOPT</code><dd>Protocol not available 160 161 <br><dt><code>ENOSPC</code><dd>No space left on device 162 163 <br><dt><code>ENOSR</code><dd>No stream resources 164 165 <br><dt><code>ENOSTR</code><dd>Not a stream 166 167 <br><dt><code>ENOSYS</code><dd>Function not implemented 168 169 <br><dt><code>ENOTBLK</code><dd>Block device required 170 171 <br><dt><code>ENOTCONN</code><dd>Socket is not connected 172 173 <br><dt><code>ENOTDIR</code><dd>Not a directory 174 175 <br><dt><code>ENOTEMPTY</code><dd>Directory not empty 176 177 <br><dt><code>ENOTSOCK</code><dd>Socket operation on non-socket 178 179 <br><dt><code>ENOTSUP</code><dd>Not supported 180 181 <br><dt><code>ENOTTY</code><dd>Not a character device 182 183 <br><dt><code>ENXIO</code><dd>No such device or address 184 185 <br><dt><code>EPERM</code><dd>Not owner 186 187 <br><dt><code>EPIPE</code><dd>Broken pipe 188 189 <br><dt><code>EPROTO</code><dd>Protocol error 190 191 <br><dt><code>EPROTOTYPE</code><dd>Protocol wrong type for socket 192 193 <br><dt><code>EPROTONOSUPPORT</code><dd>Unknown protocol 194 195 <br><dt><code>ERANGE</code><dd>Result too large 196 197 <br><dt><code>EREMOTE</code><dd>Resource is remote 198 199 <br><dt><code>EROFS</code><dd>Read-only file system 200 201 <br><dt><code>ESHUTDOWN</code><dd>Can't send after socket shutdown 202 203 <br><dt><code>ESOCKTNOSUPPORT</code><dd>Socket type not supported 204 205 <br><dt><code>ESPIPE</code><dd>Illegal seek 206 207 <br><dt><code>ESRCH</code><dd>No such process 208 209 <br><dt><code>ESRMNT</code><dd>Srmount error 210 211 <br><dt><code>ETIME</code><dd>Stream ioctl timeout 212 213 <br><dt><code>ETIMEDOUT</code><dd>Connection timed out 214 215 <br><dt><code>ETXTBSY</code><dd>Text file busy 216 217 <br><dt><code>EXDEV</code><dd>Cross-device link 218 219 <br><dt><code>ECANCELED</code><dd>Operation canceled 220 221 <br><dt><code>ENOTRECOVERABLE</code><dd>State not recoverable 222 223 <br><dt><code>EOWNERDEAD</code><dd>Previous owner died 224 225 <br><dt><code>ESTRPIPE</code><dd>Strings pipe error 226 227 </dl> 228 229 <p><code>_strerror_r</code> is a reentrant version of the above. 230 231 <p><br> 232<strong>Returns</strong><br> 233This function returns a pointer to a string. Your application must 234not modify that string. 235 236 <p><br> 237<strong>Portability</strong><br> 238ANSI C requires <code>strerror</code>, but does not specify the strings used 239for each error number. 240 241 <p>Although this implementation of <code>strerror</code> is reentrant (depending 242on <code>_user_strerror</code>), ANSI C declares that subsequent calls to 243<code>strerror</code> may overwrite the result string; therefore portable 244code cannot depend on the reentrancy of this subroutine. 245 246 <p>Although this implementation of <code>strerror</code> guarantees a non-null 247result with a NUL-terminator, some implementations return <code>NULL</code> 248on failure. Although POSIX allows <code>strerror</code> to set <code>errno</code> 249to EINVAL on failure, this implementation does not do so (unless 250you provide <code>_user_strerror</code>). 251 252 <p>POSIX recommends that unknown <var>errnum</var> result in a message 253including that value, however it is not a requirement and this 254implementation does not provide that information (unless you 255provide <code>_user_strerror</code>). 256 257 <p>This implementation of <code>strerror</code> provides for user-defined 258extensibility. <code>errno.h</code> defines <var>__ELASTERROR</var>, which can be 259used as a base for user-defined error values. If the user supplies a 260routine named <code>_user_strerror</code>, and <var>errnum</var> passed to 261<code>strerror</code> does not match any of the supported values, 262<code>_user_strerror</code> is called with three arguments. The first is of 263type <var>int</var>, and is the <var>errnum</var> value unknown to <code>strerror</code>. 264The second is of type <var>int</var>, and matches the <var>internal</var> argument 265of <code>_strerror_r</code>; this should be zero if called from <code>strerror</code> 266and non-zero if called from any other function; <code>_user_strerror</code> can 267use this information to satisfy the POSIX rule that no other 268standardized function can overwrite a static buffer reused by 269<code>strerror</code>. The third is of type <var>int *</var>, and matches the 270<var>error</var> argument of <code>_strerror_r</code>; if a non-zero value is stored 271into that location (usually <var>EINVAL</var>), then <code>strerror</code> will set 272<code>errno</code> to that value, and the XPG variant of <code>strerror_r</code> will 273return that value instead of zero or <var>ERANGE</var>. <code>_user_strerror</code> 274returns a <var>char *</var> value; returning <var>NULL</var> implies that the user 275function did not choose to handle <var>errnum</var>. The default 276<code>_user_strerror</code> returns <var>NULL</var> for all input values. Note that 277<code>_user_sterror</code> must be thread-safe, and only denote errors via the 278third argument rather than modifying <code>errno</code>, if <code>strerror</code> and 279<code>strerror_r</code> are are to comply with POSIX. 280 281 <p><code>strerror</code> requires no supporting OS subroutines. 282 283 <p><br> 284 285 </body></html> 286 287