2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
15 /* WIN32_LastError contains the last error that occurred in the
16 * Win32 API. This value should be stored separately for each
17 * thread, when we eventually get thread support.
19 static int WIN32_LastError;
21 /* The errno_xlat_table contains the errno-to-Win32 error
22 * mapping. Since this is a single table, it can't easily
23 * take into account function-specific differences, so there
24 * will probably be quite a few points where we don't exactly
25 * match what NT would return. Then again, neither does
33 /* The table looks pretty ugly due to the preprocessor stuff,
34 * but I honestly have no idea how many of these values are
35 * portable. I'm not even sure how many of them are even
38 static ERRNO_XLAT_TABLE errno_xlat_table[] = {
40 { EPERM, ERROR_ACCESS_DENIED },
43 { ENOENT, ERROR_FILE_NOT_FOUND },
46 { ESRCH, ERROR_INVALID_PARAMETER },
49 { EIO, ERROR_IO_DEVICE },
52 { ENOEXEC, ERROR_BAD_FORMAT },
55 { EBADF, ERROR_INVALID_HANDLE },
58 { ENOMEM, ERROR_OUTOFMEMORY },
61 { EACCES, ERROR_ACCESS_DENIED },
64 { EBUSY, ERROR_BUSY },
67 { EEXIST, ERROR_FILE_EXISTS },
70 { ENODEV, ERROR_BAD_DEVICE },
73 { EINVAL, ERROR_INVALID_PARAMETER },
76 { EMFILE, ERROR_TOO_MANY_OPEN_FILES },
79 { ETXTBSY, ERROR_BUSY, },
82 { ENOSPC, ERROR_DISK_FULL },
85 { ESPIPE, ERROR_SEEK_ON_DEVICE },
88 { EPIPE, ERROR_BROKEN_PIPE },
91 { EDEADLK, ERROR_POSSIBLE_DEADLOCK },
93 #if defined(ENAMETOOLONG)
94 { ENAMETOOLONG, ERROR_FILENAME_EXCED_RANGE },
96 #if defined(ENOTEMPTY)
97 { ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
102 /**********************************************************************
103 * GetLastError (KERNEL32.227)
105 DWORD GetLastError(void)
107 return WIN32_LastError;
110 /**********************************************************************
111 * SetLastError (KERNEL32.497)
113 * This is probably not used by apps too much, but it's useful for
114 * our own internal use.
116 void SetLastError(DWORD error)
118 WIN32_LastError = error;
121 DWORD ErrnoToLastError(int errno_num)
123 DWORD rc = ERROR_UNKNOWN;
126 while(errno_xlat_table[i].errno != -1)
128 if(errno_xlat_table[i].errno == errno_num)
130 rc = errno_xlat_table[i].win32err;