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