]> pd.if.org Git - pdclib/blob - platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c
Cosmetic comment fixes.
[pdclib] / platform / win32 / functions / _PDCLIB / _PDCLIB_w32errno.c
1 /* _PDCLIB_w32errno( void )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #ifndef REGTEST
8 #include <errno.h>
9 #include <wchar.h> // Watcom bug: winnt.h assumes string.h defines wchar_t
10 #include <windows.h>
11
12 void _PDCLIB_w32errno(void);
13
14 void _PDCLIB_w32errno(void)
15 {
16     // Not exhaustive
17     switch(GetLastError()) {
18         case ERROR_SUCCESS:
19             return;
20         case ERROR_FILE_NOT_FOUND:
21         case ERROR_PATH_NOT_FOUND:
22         case ERROR_INVALID_DRIVE:
23             errno = ENOENT; break;
24         case ERROR_TOO_MANY_OPEN_FILES:
25             errno = EMFILE; break;
26         case ERROR_ACCESS_DENIED:
27         case ERROR_WRITE_PROTECT:
28             errno = EPERM; break;
29         case ERROR_INVALID_HANDLE:
30             errno = EBADF; break;
31         case ERROR_NOT_ENOUGH_MEMORY:
32         case ERROR_OUTOFMEMORY:
33             errno = ENOMEM; break;
34         case ERROR_NOT_READY:
35             errno = EAGAIN; break;
36         case ERROR_BAD_LENGTH:
37             errno = EINVAL; break;
38         default:
39             // TODO: reconsider what to use here?
40             errno = ENOSYS; break;
41     }
42 }
43
44 #endif
45
46 #ifdef TEST
47 #include "_PDCLIB_test.h"
48
49 int main( void )
50 {
51     return TEST_RESULTS;
52 }
53
54 #endif