Release 990815.
[wine/multimedia.git] / win32 / error.c
blob42324c9b2e8ff4347f66087d287ab886e491a4dc
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 */
7 #include <errno.h>
8 #include "windef.h"
9 #include "winerror.h"
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. :-)
18 typedef struct {
19 int err;
20 DWORD win32err;
21 } ERRNO_XLAT_TABLE;
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. :-)
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 }
92 DWORD ErrnoToLastError(int errno_num)
94 DWORD rc = ERROR_UNKNOWN;
95 int i = 0;
97 while(errno_xlat_table[i].err != -1)
99 if(errno_xlat_table[i].err == errno_num)
101 rc = errno_xlat_table[i].win32err;
102 break;
104 i++;
107 return rc;
110 int LastErrorToErrno(DWORD lasterror)
112 int rc = 0; /* no error */
113 int i = 0;
115 while(errno_xlat_table[i].err != -1)
117 if(errno_xlat_table[i].win32err == lasterror )
119 rc = errno_xlat_table[i].err;
120 break;
122 i++;
124 return rc;