Release 970101
[wine.git] / win32 / error.c
blob44e86f70b39ff8c28f332ef9d045f61eb0888634
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 /* The errno_xlat_table contains the errno-to-Win32 error
15 * mapping. Since this is a single table, it can't easily
16 * take into account function-specific differences, so there
17 * will probably be quite a few points where we don't exactly
18 * match what NT would return. Then again, neither does
19 * Windows 95. :-)
21 typedef struct {
22 int errno;
23 DWORD win32err;
24 } ERRNO_XLAT_TABLE;
26 /* The table looks pretty ugly due to the preprocessor stuff,
27 * but I honestly have no idea how many of these values are
28 * portable. I'm not even sure how many of them are even
29 * used at all. :-)
31 static ERRNO_XLAT_TABLE errno_xlat_table[] = {
32 #if defined(EPERM)
33 { EPERM, ERROR_ACCESS_DENIED },
34 #endif
35 #if defined(ENOENT)
36 { ENOENT, ERROR_FILE_NOT_FOUND },
37 #endif
38 #if defined(ESRCH)
39 { ESRCH, ERROR_INVALID_PARAMETER },
40 #endif
41 #if defined(EIO)
42 { EIO, ERROR_IO_DEVICE },
43 #endif
44 #if defined(ENOEXEC)
45 { ENOEXEC, ERROR_BAD_FORMAT },
46 #endif
47 #if defined(EBADF)
48 { EBADF, ERROR_INVALID_HANDLE },
49 #endif
50 #if defined(ENOMEM)
51 { ENOMEM, ERROR_OUTOFMEMORY },
52 #endif
53 #if defined(EACCES)
54 { EACCES, ERROR_ACCESS_DENIED },
55 #endif
56 #if defined(EBUSY)
57 { EBUSY, ERROR_BUSY },
58 #endif
59 #if defined(EEXIST)
60 { EEXIST, ERROR_FILE_EXISTS },
61 #endif
62 #if defined(ENODEV)
63 { ENODEV, ERROR_BAD_DEVICE },
64 #endif
65 #if defined(EINVAL)
66 { EINVAL, ERROR_INVALID_PARAMETER },
67 #endif
68 #if defined(EMFILE)
69 { EMFILE, ERROR_TOO_MANY_OPEN_FILES },
70 #endif
71 #if defined(ETXTBSY)
72 { ETXTBSY, ERROR_BUSY, },
73 #endif
74 #if defined(ENOSPC)
75 { ENOSPC, ERROR_DISK_FULL },
76 #endif
77 #if defined(ESPIPE)
78 { ESPIPE, ERROR_SEEK_ON_DEVICE },
79 #endif
80 #if defined(EPIPE)
81 { EPIPE, ERROR_BROKEN_PIPE },
82 #endif
83 #if defined(EDEADLK)
84 { EDEADLK, ERROR_POSSIBLE_DEADLOCK },
85 #endif
86 #if defined(ENAMETOOLONG)
87 { ENAMETOOLONG, ERROR_FILENAME_EXCED_RANGE },
88 #endif
89 #if defined(ENOTEMPTY)
90 { ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
91 #endif
92 { -1, 0 }
95 DWORD ErrnoToLastError(int errno_num)
97 DWORD rc = ERROR_UNKNOWN;
98 int i = 0;
100 while(errno_xlat_table[i].errno != -1)
102 if(errno_xlat_table[i].errno == errno_num)
104 rc = errno_xlat_table[i].win32err;
105 break;
107 i++;
110 return rc;