Release 960824
[wine/multimedia.git] / win32 / error.c
blob8f66793b4cf4d20b7ab131125f14c4357b48f9d1
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 */
7 #include <stdio.h>
8 #include <errno.h>
9 #include "windows.h"
10 #include "winerror.h"
11 #include "stddebug.h"
12 #include "debug.h"
14 /* WIN32_LastError contains the last error that occurred in the
15 * Win32 API. This value should be stored separately for each
16 * thread, when we eventually get thread support.
18 static int WIN32_LastError;
20 /* The errno_xlat_table contains the errno-to-Win32 error
21 * mapping. Since this is a single table, it can't easily
22 * take into account function-specific differences, so there
23 * will probably be quite a few points where we don't exactly
24 * match what NT would return. Then again, neither does
25 * Windows 95. :-)
27 typedef struct {
28 int errno;
29 DWORD win32err;
30 } ERRNO_XLAT_TABLE;
32 /* The table looks pretty ugly due to the preprocessor stuff,
33 * but I honestly have no idea how many of these values are
34 * portable. I'm not even sure how many of them are even
35 * used at all. :-)
37 static ERRNO_XLAT_TABLE errno_xlat_table[] = {
38 #if defined(EPERM)
39 { EPERM, ERROR_ACCESS_DENIED },
40 #endif
41 #if defined(ENOENT)
42 { ENOENT, ERROR_FILE_NOT_FOUND },
43 #endif
44 #if defined(ESRCH)
45 { ESRCH, ERROR_INVALID_PARAMETER },
46 #endif
47 #if defined(EIO)
48 { EIO, ERROR_IO_DEVICE },
49 #endif
50 #if defined(ENOEXEC)
51 { ENOEXEC, ERROR_BAD_FORMAT },
52 #endif
53 #if defined(EBADF)
54 { EBADF, ERROR_INVALID_HANDLE },
55 #endif
56 #if defined(ENOMEM)
57 { ENOMEM, ERROR_OUTOFMEMORY },
58 #endif
59 #if defined(EACCES)
60 { EACCES, ERROR_ACCESS_DENIED },
61 #endif
62 #if defined(EBUSY)
63 { EBUSY, ERROR_BUSY },
64 #endif
65 #if defined(EEXIST)
66 { EEXIST, ERROR_FILE_EXISTS },
67 #endif
68 #if defined(ENODEV)
69 { ENODEV, ERROR_BAD_DEVICE },
70 #endif
71 #if defined(EINVAL)
72 { EINVAL, ERROR_INVALID_PARAMETER },
73 #endif
74 #if defined(EMFILE)
75 { EMFILE, ERROR_TOO_MANY_OPEN_FILES },
76 #endif
77 #if defined(ETXTBSY)
78 { ETXTBSY, ERROR_BUSY, },
79 #endif
80 #if defined(ENOSPC)
81 { ENOSPC, ERROR_DISK_FULL },
82 #endif
83 #if defined(ESPIPE)
84 { ESPIPE, ERROR_SEEK_ON_DEVICE },
85 #endif
86 #if defined(EPIPE)
87 { EPIPE, ERROR_BROKEN_PIPE },
88 #endif
89 #if defined(EDEADLK)
90 { EDEADLK, ERROR_POSSIBLE_DEADLOCK },
91 #endif
92 #if defined(ENAMETOOLONG)
93 { ENAMETOOLONG, ERROR_FILENAME_EXCED_RANGE },
94 #endif
95 #if defined(ENOTEMPTY)
96 { ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
97 #endif
98 { -1, 0 }
101 /**********************************************************************
102 * GetLastError (KERNEL32.227)
104 DWORD GetLastError(void)
106 return WIN32_LastError;
109 /**********************************************************************
110 * SetLastError (KERNEL32.497)
112 * This is probably not used by apps too much, but it's useful for
113 * our own internal use.
115 void SetLastError(DWORD error)
117 WIN32_LastError = error;
120 /**********************************************************************
121 * SetLastErrorEx (USER32.484)
123 void SetLastErrorEx(DWORD error,DWORD type) {
124 WIN32_LastError = error;
127 DWORD ErrnoToLastError(int errno_num)
129 DWORD rc = ERROR_UNKNOWN;
130 int i = 0;
132 while(errno_xlat_table[i].errno != -1)
134 if(errno_xlat_table[i].errno == errno_num)
136 rc = errno_xlat_table[i].win32err;
137 break;
139 i++;
142 return rc;