1 /* errno.cc: errno-related functions
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
11 #define _sys_nerr FOO_sys_nerr
12 #define sys_nerr FOOsys_nerr
22 /* Table to map Windows error codes to Errno values. */
23 /* FIXME: Doing things this way is a little slow. It's trivial to change
24 this into a big case statement if necessary. Left as is for now. */
26 #define X(w, e) {ERROR_##w, #w, e}
28 static const NO_COPY struct
30 DWORD w; /* windows version of error */
31 const char *s; /* text of windows version */
32 int e; /* errno version of error */
36 /* FIXME: Some of these choices are arbitrary! */
37 X (INVALID_FUNCTION, EBADRQC),
38 X (FILE_NOT_FOUND, ENOENT),
39 X (PATH_NOT_FOUND, ENOENT),
40 X (TOO_MANY_OPEN_FILES, EMFILE),
41 X (ACCESS_DENIED, EACCES),
42 X (INVALID_HANDLE, EBADF),
43 X (NOT_ENOUGH_MEMORY, ENOMEM),
44 X (INVALID_DATA, EINVAL),
45 X (OUTOFMEMORY, ENOMEM),
46 X (INVALID_DRIVE, ENODEV),
47 X (NOT_SAME_DEVICE, EXDEV),
48 X (NO_MORE_FILES, ENMFILE),
49 X (WRITE_PROTECT, EROFS),
51 X (SHARING_VIOLATION, EACCES),
52 X (LOCK_VIOLATION, EACCES),
53 X (SHARING_BUFFER_EXCEEDED, ENOLCK),
54 X (HANDLE_EOF, ENODATA),
55 X (HANDLE_DISK_FULL, ENOSPC),
56 X (NOT_SUPPORTED, ENOSYS),
57 X (REM_NOT_LIST, ENONET),
58 X (DUP_NAME, ENOTUNIQ),
59 X (BAD_NETPATH, ENOSHARE),
60 X (BAD_NET_NAME, ENOSHARE),
61 X (FILE_EXISTS, EEXIST),
62 X (CANNOT_MAKE, EPERM),
63 X (INVALID_PARAMETER, EINVAL),
64 X (NO_PROC_SLOTS, EAGAIN),
65 X (BROKEN_PIPE, EPIPE),
67 X (NO_MORE_SEARCH_HANDLES, ENFILE),
68 X (CALL_NOT_IMPLEMENTED, ENOSYS),
69 X (INVALID_NAME, ENOENT),
70 X (WAIT_NO_CHILDREN, ECHILD),
71 X (CHILD_NOT_COMPLETE, EBUSY),
72 X (DIR_NOT_EMPTY, ENOTEMPTY),
73 X (SIGNAL_REFUSED, EIO),
74 X (BAD_PATHNAME, ENOENT),
75 X (SIGNAL_PENDING, EBUSY),
76 X (MAX_THRDS_REACHED, EAGAIN),
78 X (ALREADY_EXISTS, EEXIST),
79 X (NO_SIGNAL_SENT, EIO),
80 X (FILENAME_EXCED_RANGE, EINVAL),
81 X (META_EXPANSION_TOO_LONG, EINVAL),
82 X (INVALID_SIGNAL_NUMBER, EINVAL),
83 X (THREAD_1_INACTIVE, EINVAL),
87 X (PIPE_NOT_CONNECTED, ECOMM),
88 X (MORE_DATA, EAGAIN),
89 X (DIRECTORY, ENOTDIR),
90 X (PIPE_CONNECTED, EBUSY),
91 X (PIPE_LISTENING, ECOMM),
93 X (PROCESS_ABORTED, EFAULT),
94 X (BAD_DEVICE, ENODEV),
95 X (BAD_USERNAME, EINVAL),
96 X (NOT_CONNECTED, ENOLINK),
97 X (OPEN_FILES, EAGAIN),
98 X (ACTIVE_CONNECTIONS, EAGAIN),
99 X (DEVICE_IN_USE, EAGAIN),
100 X (INVALID_AT_INTERRUPT_TIME, EINTR),
102 X (NOT_OWNER, EPERM),
103 X (END_OF_MEDIA, ENOSPC),
104 X (EOM_OVERFLOW, ENOSPC),
105 X (BEGINNING_OF_MEDIA, ESPIPE),
106 X (SETMARK_DETECTED, ESPIPE),
107 X (NO_DATA_DETECTED, ENOSPC),
108 X (POSSIBLE_DEADLOCK, EDEADLOCK),
110 X (NEGATIVE_SEEK, EINVAL),
111 X (NOT_READY, ENOMEDIUM),
112 X (DISK_FULL, ENOSPC),
113 X (NOACCESS, EFAULT),
114 X (FILE_INVALID, ENXIO),
119 geterrno_from_win_error (DWORD code, int deferrno)
121 for (int i = 0; errmap[i].w != 0; ++i)
122 if (code == errmap[i].w)
124 syscall_printf ("windows error %u == errno %d", code, errmap[i].e);
128 syscall_printf ("unknown windows error %u, setting errno to %d", code,
130 return deferrno; /* FIXME: what's so special about EACCESS? */
133 /* seterrno_from_win_error: Given a Windows error code, set errno
136 seterrno_from_win_error (const char *file, int line, DWORD code)
138 syscall_printf ("%s:%d errno %d", file, line, code);
139 set_errno (geterrno_from_win_error (code, EACCES));
143 /* seterrno: Set `errno' based on GetLastError (). */
145 seterrno (const char *file, int line)
147 seterrno_from_win_error (file, line, GetLastError ());
150 extern char *_user_strerror _PARAMS ((int));
153 const NO_COPY char __declspec(dllexport) * const _sys_errlist[]=
155 /* NOERROR 0 */ "No error",
156 /* EPERM 1 */ "Not super-user",
157 /* ENOENT 2 */ "No such file or directory",
158 /* ESRCH 3 */ "No such process",
159 /* EINTR 4 */ "Interrupted system call",
160 /* EIO 5 */ "I/O error",
161 /* ENXIO 6 */ "No such device or address",
162 /* E2BIG 7 */ "Arg list too long",
163 /* ENOEXEC 8 */ "Exec format error",
164 /* EBADF 9 */ "Bad file number",
165 /* ECHILD 10 */ "No children",
166 /* EAGAIN 11 */ "Resource temporarily unavailable",
167 /* ENOMEM 12 */ "Not enough core",
168 /* EACCES 13 */ "Permission denied",
169 /* EFAULT 14 */ "Bad address",
170 /* ENOTBLK 15 */ "Block device required",
171 /* EBUSY 16 */ "Mount device busy",
172 /* EEXIST 17 */ "File exists",
173 /* EXDEV 18 */ "Cross-device link",
174 /* ENODEV 19 */ "No such device",
175 /* ENOTDIR 20 */ "Not a directory",
176 /* EISDIR 21 */ "Is a directory",
177 /* EINVAL 22 */ "Invalid argument",
178 /* ENFILE 23 */ "Too many open files in system",
179 /* EMFILE 24 */ "Too many open files",
180 /* ENOTTY 25 */ "Not a typewriter",
181 /* ETXTBSY 26 */ "Text file busy",
182 /* EFBIG 27 */ "File too large",
183 /* ENOSPC 28 */ "No space left on device",
184 /* ESPIPE 29 */ "Illegal seek",
185 /* EROFS 30 */ "Read only file system",
186 /* EMLINK 31 */ "Too many links",
187 /* EPIPE 32 */ "Broken pipe",
188 /* EDOM 33 */ "Math arg out of domain of func",
189 /* ERANGE 34 */ "Math result not representable",
190 /* ENOMSG 35 */ "No message of desired type",
191 /* EIDRM 36 */ "Identifier removed",
192 /* ECHRNG 37 */ "Channel number out of range",
193 /* EL2NSYNC 38 */ "Level 2 not synchronized",
194 /* EL3HLT 39 */ "Level 3 halted",
195 /* EL3RST 40 */ "Level 3 reset",
196 /* ELNRNG 41 */ "Link number out of range",
197 /* EUNATCH 42 */ "Protocol driver not attached",
198 /* ENOCSI 43 */ "No CSI structure available",
199 /* EL2HLT 44 */ "Level 2 halted",
200 /* EDEADLK 45 */ "Deadlock condition",
201 /* ENOLCK 46 */ "No record locks available",
205 /* EBADE 50 */ "Invalid exchange",
206 /* EBADR 51 */ "Invalid request descriptor",
207 /* EXFULL 52 */ "Exchange full",
208 /* ENOANO 53 */ "No anode",
209 /* EBADRQC 54 */ "Invalid request code",
210 /* EBADSLT 55 */ "Invalid slot",
211 /* EDEADLOCK 56 */ "File locking deadlock error",
212 /* EBFONT 57 */ "Bad font file fmt",
215 /* ENOSTR 60 */ "Device not a stream",
216 /* ENODATA 61 */ "No data (for no delay io)",
217 /* ETIME 62 */ "Timer expired",
218 /* ENOSR 63 */ "Out of streams resources",
219 /* ENONET 64 */ "Machine is not on the network",
220 /* ENOPKG 65 */ "Package not installed",
221 /* EREMOTE 66 */ "The object is remote",
222 /* ENOLINK 67 */ "The link has been severed",
223 /* EADV 68 */ "Advertise error",
224 /* ESRMNT 69 */ "Srmount error",
225 /* ECOMM 70 */ "Communication error on send",
226 /* EPROTO 71 */ "Protocol error",
229 /* EMULTIHOP 74 */ "Multihop attempted",
230 /* ELBIN 75 */ "Inode is remote (not really error)",
231 /* EDOTDOT 76 */ "Cross mount point (not really error)",
232 /* EBADMSG 77 */ "Trying to read unreadable message",
235 /* ENOTUNIQ 80 */ "Given log. name not unique",
236 /* EBADFD 81 */ "f.d. invalid for this operation",
237 /* EREMCHG 82 */ "Remote address changed",
238 /* ELIBACC 83 */ "Can't access a needed shared lib",
239 /* ELIBBAD 84 */ "Accessing a corrupted shared lib",
240 /* ELIBSCN 85 */ ".lib section in a.out corrupted",
241 /* ELIBMAX 86 */ "Attempting to link in too many libs",
242 /* ELIBEXEC 87 */ "Attempting to exec a shared library",
243 /* ENOSYS 88 */ "Function not implemented",
244 /* ENMFILE 89 */ "No more files",
245 /* ENOTEMPTY 90 */ "Directory not empty",
246 /* ENAMETOOLONG 91 */ "File or path name too long",
247 /* ELOOP 92 */ "Too many symbolic links",
250 /* EOPNOTSUPP 95 */ "Operation not supported on transport endpoint",
251 /* EPFNOSUPPORT 96 */ "Protocol family not supported",
259 /* ECONNRESET 104 */ "Connection reset by peer",
260 /* ENOBUFS 105 */ "No buffer space available",
261 /* EAFNOSUPPORT 106 */ "Address family not supported by protocol",
262 /* EPROTOTYPE 107 */ "Protocol wrong type for transport endpoint",
263 /* ENOTSOCK 108 */ "Socket operation on non-socket",
264 /* ENOPROTOOPT 109 */ "Protocol not available",
265 /* ESHUTDOWN 110 */ "Cannot send after transport endpoint shutdown",
266 /* ECONNREFUSED 111 */ "Connection refused",
267 /* EADDRINUSE 112 */ "Address already in use",
268 /* ECONNABORTED 113 */ "Connection aborted",
269 /* ENETUNREACH 114 */ "Network is unreachable",
270 /* ENETDOWN 115 */ "Network is down",
271 /* ETIMEDOUT 116 */ "Connection timed out",
272 /* EHOSTDOWN 117 */ "Host is down",
273 /* EHOSTUNREACH 118 */ "No route to host",
274 /* EINPROGRESS 119 */ "Operation now in progress",
275 /* EALREADY 120 */ "Operation already in progress",
276 /* EDESTADDRREQ 121 */ "Destination address required",
277 /* EMSGSIZE 122 */ "Message too long",
278 /* EPROTONOSUPPORT 123 */ "Protocol not supported",
279 /* ESOCKTNOSUPPORT 124 */ "Socket type not supported",
280 /* EADDRNOTAVAIL 125 */ "Cannot assign requested address",
281 /* ENETRESET 126 */ "Network dropped connection because of reset",
282 /* EISCONN 127 */ "Transport endpoint is already connected",
283 /* ENOTCONN 128 */ "Transport endpoint is not connected",
284 /* ETOOMANYREFS 129 */ "Too many references: cannot splice",
285 /* EPROCLIM 130 */ "Process limit exceeded",
286 /* EUSERS 131 */ "Too many users",
287 /* EDQUOT 132 */ "Quota exceeded",
288 /* ESTALE 133 */ "Stale NFS file handle",
289 /* ENOTSUP 134 */ "134",
290 /* ENOMEDIUM 135 */ "no medium",
291 /* ENOSHARE 136 */ "No such host or network path",
292 /* ECASECLASH 137 */ "Filename exists with different case"
295 extern int const NO_COPY __declspec(dllexport) _sys_nerr = sizeof (_sys_errlist) / sizeof (_sys_errlist[0]);
298 /* FIXME: Why is strerror() a long switch and not just:
299 return sys_errlist[errnum];
300 (or moral equivalent).
301 Some entries in sys_errlist[] don't match the corresponding
302 entries in strerror(). This seems odd.
305 /* CYGWIN internal */
306 /* strerror: convert from errno values to error strings */
308 strerror (int errnum)
317 error = "No such file or directory";
320 error = "No such process";
323 error = "Interrupted system call";
329 error = "No such device or address";
332 error = "Arg list too long";
335 error = "Exec format error";
338 error = "Bad file number";
341 error = "No children";
344 error = "Resource temporarily unavailable";
347 error = "Not enough memory";
350 error = "Permission denied";
353 error = "Bad address";
356 error = "Block device required";
359 error = "Device or resource busy";
362 error = "File exists";
365 error = "Cross-device link";
368 error = "No such device";
371 error = "Not a directory";
374 error = "Is a directory";
377 error = "Invalid argument";
380 error = "Too many open files in system";
383 error = "Too many open files";
386 error = "Not a character device";
389 error = "Text file busy";
392 error = "File too large";
395 error = "No space left on device";
398 error = "Illegal seek";
401 error = "Read-only file system";
404 error = "Too many links";
407 error = "Broken pipe";
410 error = "Math arg out of domain of func";
413 error = "Math result out of range";
416 error = "No message of desired type";
419 error = "Identifier removed";
422 error = "Channel number out of range";
425 error = "Level 2 not synchronized";
428 error = "Level 3 halted";
431 error = "Level 3 reset";
434 error = "Link number out of range";
437 error = "Protocol driver not attached";
440 error = "No CSI structure available";
443 error = "Level 2 halted";
446 error = "Deadlock condition";
452 error = "Invalid exchange";
455 error = "Invalid request descriptor";
458 error = "Exchange full";
464 error = "Invalid request code";
467 error = "Invalid slot";
470 error = "File locking deadlock error";
473 error = "Bad font file fmt";
476 error = "Not a stream";
479 error = "No data (for no delay io)";
482 error = "Stream ioctl timeout";
485 error = "No stream resources";
488 error = "Machine is not on the network";
491 error = "No package";
494 error = "Resource is remote";
497 error = "Virtual circuit is gone";
500 error = "Advertise error";
503 error = "Srmount error";
506 error = "Communication error";
509 error = "Protocol error";
512 error = "Multihop attempted";
515 error = "Inode is remote (not really error)";
518 error = "Cross mount point (not really error)";
521 error = "Bad message";
524 error = "Given log. name not unique";
527 error = "f.d. invalid for this operation";
530 error = "Remote address changed";
533 error = "Cannot access a needed shared library";
536 error = "Accessing a corrupted shared library";
539 error = ".lib section in a.out corrupted";
542 error = "Attempting to link in more shared libraries than system limit";
545 error = "Cannot exec a shared library directly";
548 error = "Function not implemented";
551 error = "No more files";
554 error = "Directory not empty";
557 error = "File or path name too long";
560 error = "Too many symbolic links";
563 error = "Operation not supported on transport endpoint";
566 error = "Protocol family not supported";
569 error = "Connection reset by peer";
572 error = "No buffer space available; the socket cannot be connected";
575 error = "Addresses in the specified family cannot be used with this socket";
578 error = "errno EPROTOTYPE triggered";
581 error = "The descriptor is a file, not a socket";
584 error = "This option is unsupported";
587 error = "errno ESHUTDOWN triggered";
590 error = "Connection refused";
593 error = "Address already in use";
596 error = "The connection was aborted";
599 error ="The network can't be reached from this host at this time";
602 error = "Network failed.";
605 error = "Attempt to connect timed out without establishing a connection";
608 error = "errno EHOSTDOWN triggered";
611 error = "errno EHOSTUNREACH triggered";
614 error = "errno EINPROGRESS triggered";
617 error = "errno EALREADY triggered";
620 error = "errno EDESTADDRREQ triggered";
623 error = "errno EMSGSIZE triggered";
626 case EPROTONOSUPPORT:
627 error = "errno EPROTONOSUPPORT triggered";
629 case ESOCKTNOSUPPORT:
630 error = "errno ESOCKTNOSUPPORT triggered";
633 error = "errno EADDRNOTAVAIL triggered";
636 error = "errno ENETRESET triggered";
639 error = "The socket is already connected";
642 error = "The socket is not connected";
645 error = "errno ETOOMANYREFS triggered";
648 error = "errno EPROCLIM triggered";
651 error = "errno EUSERS triggered";
654 error = "errno EDQUOT triggered";
657 error = "errno ESTALE triggered";
660 error = "errno ENOTSUP triggered";
666 error = "No such host or network path";
669 error = "Filename exists with different case";
673 char *buf= _reent_winsup()->_strerror_buf;
675 static NO_COPY char buf[20];
677 __small_sprintf (buf, "error %d", errnum);
682 /* FIXME: strerror should really be const in the appropriate newlib
684 return (char *) error;