1 # define EINVAL		ERROR_BAD_ARGUMENTS
2 # define ENOMEM		ERROR_OUTOFMEMORY
3 # define EMEDIUMTYPE	ERROR_MEDIA_INCOMPATIBLE
4 # define ENOMEDIUM	ERROR_MEDIA_OFFLINE
5 # define ENODEV		ERROR_BAD_COMMAND
6 # define EAGAIN		ERROR_NOT_READY
7 # define ENOSPC		ERROR_DISK_FULL
8 # define EIO		ERROR_NOT_SUPPORTED
9 # define ENXIO		ERROR_GEN_FAILURE
10 # define EBUSY		ERROR_SHARING_VIOLATION
11 # define ENOENT		ERROR_FILE_NOT_FOUND
12 # define ENOTDIR	ERROR_NO_VOLUME_LABEL
13 # define EINTR		ERROR_OPERATION_ABORTED
14 # define FATAL_START(e)	(0x10000|(e))
15 # define FATAL_MASK	 0x0FFFF
16 
17 #ifdef errno
18 # undef errno
19 #endif
20 
21 #ifdef __cplusplus
22 static class __win32_errno__ {
23     public:
24 	operator int()		{ return GetLastError(); }
25 	int operator=(int e)	{ SetLastError(e); return e; }
26 } win32_errno;
27 # define errno		win32_errno
28 #else
29 # define errno		(GetLastError())
30 #endif
31 
32 #define set_errno(e)	(SetLastError(e),e)
33 
34 #ifdef perror
35 #undef perror
36 #endif
37 #define perror win32_perror
win32_perror(const char * str)38 static void win32_perror (const char *str)
39 { LPSTR lpMsgBuf;
40 
41     FormatMessageA(
42 	FORMAT_MESSAGE_ALLOCATE_BUFFER |
43 	FORMAT_MESSAGE_FROM_SYSTEM |
44 	FORMAT_MESSAGE_IGNORE_INSERTS,
45 	NULL,
46 	GetLastError(),
47 	0, // Default language
48 	(LPSTR) &lpMsgBuf,
49 	0,
50 	NULL
51 	);
52     if (str)
53 	fprintf (stderr,"%s: %s",str,lpMsgBuf);
54     else
55 	fprintf (stderr,"%s",lpMsgBuf);
56 
57     LocalFree(lpMsgBuf);
58 }
59