comparison src/sysdep.c @ 255:084402c475ba r20-5b26

Import from CVS: tag r20-5b26
author cvs
date Mon, 13 Aug 2007 10:21:18 +0200
parents 677f6a0ee643
children 11cf20601dec
comparison
equal deleted inserted replaced
254:e92abcaa252b 255:084402c475ba
78 #include "syssignal.h" 78 #include "syssignal.h"
79 #endif 79 #endif
80 #ifndef WINDOWSNT 80 #ifndef WINDOWSNT
81 #include <sys/times.h> 81 #include <sys/times.h>
82 #endif 82 #endif
83
83 #ifdef WINDOWSNT 84 #ifdef WINDOWSNT
84 #include <sys/utime.h> 85 #include <sys/utime.h>
86 #include <windows.h>
85 #include "ntheap.h" 87 #include "ntheap.h"
86 #endif 88 #endif
87 89
88 /* ------------------------------- */ 90 /* ------------------------------- */
89 /* TTY definitions */ 91 /* TTY definitions */
2372 2374
2373 #endif /* HAVE_SIGBLOCK (HAVE_SIGPROCMASK) */ 2375 #endif /* HAVE_SIGBLOCK (HAVE_SIGPROCMASK) */
2374 2376
2375 2377
2376 /************************************************************************/ 2378 /************************************************************************/
2377 /* Emulation of strerror() */ 2379 /* Emulation of strerror() and errno support */
2378 /************************************************************************/ 2380 /************************************************************************/
2379 2381
2380 #ifndef HAVE_STRERROR 2382 #ifndef HAVE_STRERROR
2381 2383
2382 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__) 2384 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__)
2401 return ((CONST char *) GETTEXT ("Unknown error")); 2403 return ((CONST char *) GETTEXT ("Unknown error"));
2402 } 2404 }
2403 2405
2404 #endif /* ! HAVE_STRERROR */ 2406 #endif /* ! HAVE_STRERROR */
2405 2407
2408 #ifdef WINDOWSNT
2409
2410 struct errentry {
2411 unsigned long oscode; /* Win32 error */
2412 int errnocode; /* unix errno */
2413 };
2414
2415 static struct errentry errtable[] = {
2416 { ERROR_INVALID_FUNCTION, EINVAL }, /* 1 */
2417 { ERROR_FILE_NOT_FOUND, ENOENT }, /* 2 */
2418 { ERROR_PATH_NOT_FOUND, ENOENT }, /* 3 */
2419 { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, /* 4 */
2420 { ERROR_ACCESS_DENIED, EACCES }, /* 5 */
2421 { ERROR_INVALID_HANDLE, EBADF }, /* 6 */
2422 { ERROR_ARENA_TRASHED, ENOMEM }, /* 7 */
2423 { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, /* 8 */
2424 { ERROR_INVALID_BLOCK, ENOMEM }, /* 9 */
2425 { ERROR_BAD_ENVIRONMENT, E2BIG }, /* 10 */
2426 { ERROR_BAD_FORMAT, ENOEXEC }, /* 11 */
2427 { ERROR_INVALID_ACCESS, EINVAL }, /* 12 */
2428 { ERROR_INVALID_DATA, EINVAL }, /* 13 */
2429 { ERROR_INVALID_DRIVE, ENOENT }, /* 15 */
2430 { ERROR_CURRENT_DIRECTORY, EACCES }, /* 16 */
2431 { ERROR_NOT_SAME_DEVICE, EXDEV }, /* 17 */
2432 { ERROR_NO_MORE_FILES, ENOENT }, /* 18 */
2433 { ERROR_LOCK_VIOLATION, EACCES }, /* 33 */
2434 { ERROR_BAD_NETPATH, ENOENT }, /* 53 */
2435 { ERROR_NETWORK_ACCESS_DENIED, EACCES }, /* 65 */
2436 { ERROR_BAD_NET_NAME, ENOENT }, /* 67 */
2437 { ERROR_FILE_EXISTS, EEXIST }, /* 80 */
2438 { ERROR_CANNOT_MAKE, EACCES }, /* 82 */
2439 { ERROR_FAIL_I24, EACCES }, /* 83 */
2440 { ERROR_INVALID_PARAMETER, EINVAL }, /* 87 */
2441 { ERROR_NO_PROC_SLOTS, EAGAIN }, /* 89 */
2442 { ERROR_DRIVE_LOCKED, EACCES }, /* 108 */
2443 { ERROR_BROKEN_PIPE, EPIPE }, /* 109 */
2444 { ERROR_DISK_FULL, ENOSPC }, /* 112 */
2445 { ERROR_INVALID_TARGET_HANDLE, EBADF }, /* 114 */
2446 { ERROR_INVALID_HANDLE, EINVAL }, /* 124 */
2447 { ERROR_WAIT_NO_CHILDREN, ECHILD }, /* 128 */
2448 { ERROR_CHILD_NOT_COMPLETE, ECHILD }, /* 129 */
2449 { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, /* 130 */
2450 { ERROR_NEGATIVE_SEEK, EINVAL }, /* 131 */
2451 { ERROR_SEEK_ON_DEVICE, EACCES }, /* 132 */
2452 { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, /* 145 */
2453 { ERROR_NOT_LOCKED, EACCES }, /* 158 */
2454 { ERROR_BAD_PATHNAME, ENOENT }, /* 161 */
2455 { ERROR_MAX_THRDS_REACHED, EAGAIN }, /* 164 */
2456 { ERROR_LOCK_FAILED, EACCES }, /* 167 */
2457 { ERROR_ALREADY_EXISTS, EEXIST }, /* 183 */
2458 { ERROR_FILENAME_EXCED_RANGE, ENOENT }, /* 206 */
2459 { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, /* 215 */
2460 { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } /* 1816 */
2461 };
2462
2463 /* The following two constants must be the minimum and maximum
2464 values in the (contiguous) range of Exec Failure errors. */
2465 #define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
2466 #define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
2467
2468 /* These are the low and high value in the range of errors that are
2469 access violations */
2470 #define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
2471 #define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
2472
2473 void
2474 mswindows_set_errno (unsigned long win32_error)
2475 {
2476 int i;
2477
2478 /* check the table for the OS error code */
2479 for (i = 0; i < sizeof(errtable)/sizeof(errtable[0]); ++i)
2480 {
2481 if (win32_error == errtable[i].oscode)
2482 {
2483 errno = errtable[i].errnocode;
2484 return;
2485 }
2486 }
2487
2488 /* The error code wasn't in the table. We check for a range of
2489 * EACCES errors or exec failure errors (ENOEXEC). Otherwise EINVAL is
2490 * returned. */
2491 if (win32_error >= MIN_EACCES_RANGE && win32_error <= MAX_EACCES_RANGE)
2492 errno = EACCES;
2493 else if (win32_error >= MIN_EXEC_ERROR && win32_error <= MAX_EXEC_ERROR)
2494 errno = ENOEXEC;
2495 else
2496 errno = EINVAL;
2497 }
2498
2499 void
2500 mswindows_set_last_errno (void)
2501 {
2502 mswindows_set_errno (GetLastError ());
2503 }
2504
2505 #endif /* WINDOWSNT */
2406 2506
2407 2507
2408 /************************************************************************/ 2508 /************************************************************************/
2409 /* Encapsulations of system calls */ 2509 /* Encapsulations of system calls */
2410 /************************************************************************/ 2510 /************************************************************************/