2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
13 /* The errno_xlat_table contains the errno-to-Win32 error
14 * mapping. Since this is a single table, it can't easily
15 * take into account function-specific differences, so there
16 * will probably be quite a few points where we don't exactly
17 * match what NT would return. Then again, neither does
25 /* The table looks pretty ugly due to the preprocessor stuff,
26 * but I honestly have no idea how many of these values are
27 * portable. I'm not even sure how many of them are even
30 static ERRNO_XLAT_TABLE errno_xlat_table[] = {
32 { EPERM, ERROR_ACCESS_DENIED },
35 { ENOENT, ERROR_FILE_NOT_FOUND },
38 { ESRCH, ERROR_INVALID_PARAMETER },
41 { EIO, ERROR_IO_DEVICE },
44 { ENOEXEC, ERROR_BAD_FORMAT },
47 { EBADF, ERROR_INVALID_HANDLE },
50 { ENOMEM, ERROR_OUTOFMEMORY },
53 { EACCES, ERROR_ACCESS_DENIED },
56 { EBUSY, ERROR_BUSY },
59 { EEXIST, ERROR_FILE_EXISTS },
62 { ENODEV, ERROR_BAD_DEVICE },
65 { EINVAL, ERROR_INVALID_PARAMETER },
68 { EMFILE, ERROR_TOO_MANY_OPEN_FILES },
71 { ETXTBSY, ERROR_BUSY, },
74 { ENOSPC, ERROR_DISK_FULL },
77 { ESPIPE, ERROR_SEEK_ON_DEVICE },
80 { EPIPE, ERROR_BROKEN_PIPE },
83 { EDEADLK, ERROR_POSSIBLE_DEADLOCK },
85 #if defined(ENAMETOOLONG)
86 { ENAMETOOLONG, ERROR_FILENAME_EXCED_RANGE },
88 #if defined(ENOTEMPTY)
89 { ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
94 DWORD ErrnoToLastError(int errno_num)
96 DWORD rc = ERROR_UNKNOWN;
99 while(errno_xlat_table[i].err != -1)
101 if(errno_xlat_table[i].err == errno_num)
103 rc = errno_xlat_table[i].win32err;
112 int LastErrorToErrno(DWORD lasterror)
114 int rc = 0; /* no error */
117 while(errno_xlat_table[i].err != -1)
119 if(errno_xlat_table[i].win32err == lasterror )
121 rc = errno_xlat_table[i].err;