]> pd.if.org Git - pdclib/blob - platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c
dos2unix
[pdclib] / platform / win32 / functions / _PDCLIB / _PDCLIB_w32errno.c
1 /* _PDCLIB_allocpages( int const )
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 /* This is a stub implementation of _PDCLIB_allocpages
8 */
9
10 #ifndef REGTEST
11 #include <errno.h>
12 #include <wchar.h> // Watcom bug: winnt.h assumes string.h defines wchar_t
13 #include <windows.h>
14
15 void _PDCLIB_w32errno(void);
16
17 void _PDCLIB_w32errno(void)
18 {
19     // Not exhaustive
20     switch(GetLastError()) {
21         case ERROR_SUCCESS:
22             return;
23         case ERROR_FILE_NOT_FOUND:
24         case ERROR_PATH_NOT_FOUND:
25         case ERROR_INVALID_DRIVE:
26             errno = ENOENT; break;
27         case ERROR_TOO_MANY_OPEN_FILES:
28             errno = EMFILE; break;
29         case ERROR_ACCESS_DENIED:
30         case ERROR_WRITE_PROTECT:
31             errno = EPERM; break;
32         case ERROR_INVALID_HANDLE:
33             errno = EBADF; break;
34         case ERROR_NOT_ENOUGH_MEMORY:
35         case ERROR_OUTOFMEMORY:
36             errno = ENOMEM; break;
37         case ERROR_NOT_READY:
38             errno = EAGAIN; break;
39         case ERROR_BAD_LENGTH:
40             errno = EINVAL; break;
41         default:
42             // TODO: reconsider what to use here?
43             errno = ENOSYS; break;
44     }
45 }
46
47 #endif
48
49 #ifdef TEST
50 #include "_PDCLIB_test.h"
51
52 int main( void )
53 {
54     return TEST_RESULTS;
55 }
56
57 #endif