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