2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
14 /* The errno_xlat_table contains the errno-to-Win32 error
15 * mapping. Since this is a single table, it can't easily
16 * take into account function-specific differences, so there
17 * will probably be quite a few points where we don't exactly
18 * match what NT would return. Then again, neither does
26 /* The table looks pretty ugly due to the preprocessor stuff,
27 * but I honestly have no idea how many of these values are
28 * portable. I'm not even sure how many of them are even
31 static ERRNO_XLAT_TABLE errno_xlat_table[] = {
33 { EPERM, ERROR_ACCESS_DENIED },
36 { ENOENT, ERROR_FILE_NOT_FOUND },
39 { ESRCH, ERROR_INVALID_PARAMETER },
42 { EIO, ERROR_IO_DEVICE },
45 { ENOEXEC, ERROR_BAD_FORMAT },
48 { EBADF, ERROR_INVALID_HANDLE },
51 { ENOMEM, ERROR_OUTOFMEMORY },
54 { EACCES, ERROR_ACCESS_DENIED },
57 { EBUSY, ERROR_BUSY },
60 { EEXIST, ERROR_FILE_EXISTS },
63 { ENODEV, ERROR_BAD_DEVICE },
66 { EINVAL, ERROR_INVALID_PARAMETER },
69 { EMFILE, ERROR_TOO_MANY_OPEN_FILES },
72 { ETXTBSY, ERROR_BUSY, },
75 { ENOSPC, ERROR_DISK_FULL },
78 { ESPIPE, ERROR_SEEK_ON_DEVICE },
81 { EPIPE, ERROR_BROKEN_PIPE },
84 { EDEADLK, ERROR_POSSIBLE_DEADLOCK },
86 #if defined(ENAMETOOLONG)
87 { ENAMETOOLONG, ERROR_FILENAME_EXCED_RANGE },
89 #if defined(ENOTEMPTY)
90 { ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
95 DWORD ErrnoToLastError(int errno_num)
97 DWORD rc = ERROR_UNKNOWN;
100 while(errno_xlat_table[i].errno != -1)
102 if(errno_xlat_table[i].errno == errno_num)
104 rc = errno_xlat_table[i].win32err;
113 int LastErrorToErrno(DWORD lasterror)
115 int rc = 0; /* no error */
118 while(errno_xlat_table[i].errno != -1)
120 if(errno_xlat_table[i].win32err == lasterror )
122 rc = errno_xlat_table[i].errno;