Fixed handling of DGA2.0 keyboard events.
[wine] / win32 / error.c
1 /*
2  * Win32 kernel functions
3  *
4  * Copyright 1995 Martin von Loewis and Cameron Heide
5  */
6
7 #include <errno.h>
8 #include "windef.h"
9 #include "winerror.h"
10
11 /* The errno_xlat_table contains the errno-to-Win32 error
12  * mapping.  Since this is a single table, it can't easily
13  * take into account function-specific differences, so there
14  * will probably be quite a few points where we don't exactly
15  * match what NT would return.  Then again, neither does
16  * Windows 95. :-)
17  */
18 typedef struct {
19     int         err;
20     DWORD       win32err;
21 } ERRNO_XLAT_TABLE;
22
23 /* The table looks pretty ugly due to the preprocessor stuff,
24  * but I honestly have no idea how many of these values are
25  * portable.  I'm not even sure how many of them are even
26  * used at all. :-)
27  */
28 static ERRNO_XLAT_TABLE errno_xlat_table[] = {
29 #if defined(EPERM)
30     {   EPERM,          ERROR_ACCESS_DENIED             },
31 #endif
32 #if defined(ENOENT)
33     {   ENOENT,         ERROR_FILE_NOT_FOUND            },
34 #endif
35 #if defined(ESRCH)
36     {   ESRCH,          ERROR_INVALID_PARAMETER         },
37 #endif
38 #if defined(EIO)
39     {   EIO,            ERROR_IO_DEVICE                 },
40 #endif
41 #if defined(ENOEXEC)
42     {   ENOEXEC,        ERROR_BAD_FORMAT                },
43 #endif
44 #if defined(EBADF)
45     {   EBADF,          ERROR_INVALID_HANDLE            },
46 #endif
47 #if defined(ENOMEM)
48     {   ENOMEM,         ERROR_OUTOFMEMORY               },
49 #endif
50 #if defined(EACCES)
51     {   EACCES,         ERROR_ACCESS_DENIED             },
52 #endif
53 #if defined(EBUSY)
54     {   EBUSY,          ERROR_BUSY                      },
55 #endif
56 #if defined(EEXIST)
57     {   EEXIST,         ERROR_FILE_EXISTS               },
58 #endif
59 #if defined(ENODEV)
60     {   ENODEV,         ERROR_BAD_DEVICE                },
61 #endif
62 #if defined(EINVAL)
63     {   EINVAL,         ERROR_INVALID_PARAMETER         },
64 #endif
65 #if defined(EMFILE)
66     {   EMFILE,         ERROR_TOO_MANY_OPEN_FILES       },
67 #endif
68 #if defined(ETXTBSY)
69     {   ETXTBSY,        ERROR_BUSY,                     },
70 #endif
71 #if defined(ENOSPC)
72     {   ENOSPC,         ERROR_DISK_FULL                 },
73 #endif
74 #if defined(ESPIPE)
75     {   ESPIPE,         ERROR_SEEK_ON_DEVICE            },
76 #endif
77 #if defined(EPIPE)
78     {   EPIPE,          ERROR_BROKEN_PIPE               },
79 #endif
80 #if defined(EDEADLK)
81     {   EDEADLK,        ERROR_POSSIBLE_DEADLOCK         },
82 #endif
83 #if defined(ENAMETOOLONG)
84     {   ENAMETOOLONG,   ERROR_FILENAME_EXCED_RANGE      },
85 #endif
86 #if defined(ENOTEMPTY)
87     {   ENOTEMPTY,      ERROR_DIR_NOT_EMPTY             },
88 #endif
89     {   -1,             0                               }
90 };
91
92 DWORD ErrnoToLastError(int errno_num)
93 {
94     DWORD rc = ERROR_UNKNOWN;
95     int i = 0;
96
97     while(errno_xlat_table[i].err != -1)
98     {
99         if(errno_xlat_table[i].err == errno_num)
100         {
101             rc = errno_xlat_table[i].win32err;
102             break;
103         }
104         i++;
105     }
106
107     return rc;
108 }
109
110 int LastErrorToErrno(DWORD lasterror)
111 {
112     int rc = 0; /* no error */
113     int i = 0;
114
115     while(errno_xlat_table[i].err != -1)
116     {
117         if(errno_xlat_table[i].win32err == lasterror )
118         {
119             rc = errno_xlat_table[i].err;
120             break;
121         }
122         i++;
123     }
124     return rc;
125 }