2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
14 /* WIN32_LastError contains the last error that occurred in the
15 * Win32 API. This value should be stored separately for each
16 * thread, when we eventually get thread support.
18 static int WIN32_LastError
;
20 /* The errno_xlat_table contains the errno-to-Win32 error
21 * mapping. Since this is a single table, it can't easily
22 * take into account function-specific differences, so there
23 * will probably be quite a few points where we don't exactly
24 * match what NT would return. Then again, neither does
32 /* The table looks pretty ugly due to the preprocessor stuff,
33 * but I honestly have no idea how many of these values are
34 * portable. I'm not even sure how many of them are even
37 static ERRNO_XLAT_TABLE errno_xlat_table
[] = {
39 { EPERM
, ERROR_ACCESS_DENIED
},
42 { ENOENT
, ERROR_FILE_NOT_FOUND
},
45 { ESRCH
, ERROR_INVALID_PARAMETER
},
48 { EIO
, ERROR_IO_DEVICE
},
51 { ENOEXEC
, ERROR_BAD_FORMAT
},
54 { EBADF
, ERROR_INVALID_HANDLE
},
57 { ENOMEM
, ERROR_OUTOFMEMORY
},
60 { EACCES
, ERROR_ACCESS_DENIED
},
63 { EBUSY
, ERROR_BUSY
},
66 { EEXIST
, ERROR_FILE_EXISTS
},
69 { ENODEV
, ERROR_BAD_DEVICE
},
72 { EINVAL
, ERROR_INVALID_PARAMETER
},
75 { EMFILE
, ERROR_TOO_MANY_OPEN_FILES
},
78 { ETXTBSY
, ERROR_BUSY
, },
81 { ENOSPC
, ERROR_DISK_FULL
},
84 { ESPIPE
, ERROR_SEEK_ON_DEVICE
},
87 { EPIPE
, ERROR_BROKEN_PIPE
},
90 { EDEADLK
, ERROR_POSSIBLE_DEADLOCK
},
92 #if defined(ENAMETOOLONG)
93 { ENAMETOOLONG
, ERROR_FILENAME_EXCED_RANGE
},
95 #if defined(ENOTEMPTY)
96 { ENOTEMPTY
, ERROR_DIR_NOT_EMPTY
},
101 /**********************************************************************
102 * GetLastError (KERNEL.148) (KERNEL32.227)
104 DWORD
GetLastError(void)
106 return WIN32_LastError
;
109 /**********************************************************************
110 * SetLastError (KERNEL.147) (KERNEL32.497)
112 * This is probably not used by apps too much, but it's useful for
113 * our own internal use.
115 void SetLastError(DWORD error
)
117 WIN32_LastError
= error
;
120 /**********************************************************************
121 * SetLastErrorEx (USER32.484)
123 void SetLastErrorEx(DWORD error
,DWORD type
) {
124 WIN32_LastError
= error
;
127 DWORD
ErrnoToLastError(int errno_num
)
129 DWORD rc
= ERROR_UNKNOWN
;
132 while(errno_xlat_table
[i
].errno
!= -1)
134 if(errno_xlat_table
[i
].errno
== errno_num
)
136 rc
= errno_xlat_table
[i
].win32err
;