[merp] Remove dead code (#20043)
[mono-project.git] / mono / metadata / w32error-unix.c
blobfa884f8b1a3d0c3c05cbc2580dedccf531c5d226
1 /**
2 * \file
3 */
5 #include "w32error.h"
7 #include "utils/mono-lazy-init.h"
9 static mono_lazy_init_t error_key_once = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
11 static pthread_key_t error_key;
13 static void
14 error_key_init (void)
16 gint ret;
17 ret = pthread_key_create (&error_key, NULL);
18 g_assert (ret == 0);
21 guint32
22 mono_w32error_get_last (void)
24 mono_lazy_initialize (&error_key_once, error_key_init);
25 return GPOINTER_TO_UINT (pthread_getspecific (error_key));
28 void
29 mono_w32error_set_last (guint32 error)
31 gint ret;
32 mono_lazy_initialize (&error_key_once, error_key_init);
33 ret = pthread_setspecific (error_key, GUINT_TO_POINTER (error));
34 g_assert (ret == 0);
37 guint32
38 mono_w32error_unix_to_win32 (guint32 error)
40 /* mapping ideas borrowed from wine. they may need some work */
42 switch (error) {
43 case EACCES:
44 case EPERM:
45 case EROFS: return ERROR_ACCESS_DENIED;
46 case EAGAIN: return ERROR_SHARING_VIOLATION;
47 case EBUSY: return ERROR_LOCK_VIOLATION;
48 case EEXIST: return ERROR_FILE_EXISTS;
49 case EINVAL:
50 case ESPIPE: return ERROR_SEEK;
51 case EISDIR: return ERROR_CANNOT_MAKE;
52 case ENFILE:
53 case EMFILE: return ERROR_TOO_MANY_OPEN_FILES;
54 case ENOENT:
55 case ENOTDIR: return ERROR_FILE_NOT_FOUND;
56 case ENOSPC: return ERROR_HANDLE_DISK_FULL;
57 #if !defined(_AIX) || (defined(_AIX) && defined(_LINUX_SOURCE_COMPAT))
58 case ENOTEMPTY: return ERROR_DIR_NOT_EMPTY;
59 #endif
60 case ENOEXEC: return ERROR_BAD_FORMAT;
61 case ENAMETOOLONG: return ERROR_FILENAME_EXCED_RANGE;
62 #ifdef EINPROGRESS
63 case EINPROGRESS: return ERROR_IO_PENDING;
64 #endif
65 case ENOSYS: return ERROR_NOT_SUPPORTED;
66 case EBADF: return ERROR_INVALID_HANDLE;
67 case EIO: return ERROR_INVALID_HANDLE;
68 #ifdef ERESTART
69 case ERESTART:
70 #endif
71 case EINTR: return ERROR_IO_PENDING; /* best match I could find */
72 case EPIPE: return ERROR_WRITE_FAULT;
73 case ELOOP: return ERROR_CANT_RESOLVE_FILENAME;
74 #ifdef ENODEV
75 case ENODEV: return ERROR_DEV_NOT_EXIST;
76 #endif
77 #ifdef ENXIO
78 case ENXIO: return ERROR_DEV_NOT_EXIST;
79 #endif
80 #ifdef ENOTCONN
81 case ENOTCONN: return ERROR_DEV_NOT_EXIST;
82 #endif
83 #ifdef EHOSTDOWN
84 case EHOSTDOWN: return ERROR_DEV_NOT_EXIST;
85 #endif
86 #ifdef ENEEDAUTH
87 case ENEEDAUTH: return ERROR_ACCESS_DENIED;
88 #endif
90 default:
91 g_warning ("%s: unknown error (%d) \"%s\"", __FILE__, error, g_strerror (error));
92 return ERROR_NOT_SUPPORTED;