1 | /*
|
---|
2 | * msvcrt.dll errno functions
|
---|
3 | *
|
---|
4 | * Copyright 2000 Jon Griffiths
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef __MINIVCRT__
|
---|
22 |
|
---|
23 | #include "msvcrt.h"
|
---|
24 | #include "msvcrt/errno.h"
|
---|
25 |
|
---|
26 | #include <stdio.h>
|
---|
27 | #include <string.h>
|
---|
28 |
|
---|
29 | #include "msvcrt/conio.h"
|
---|
30 | #include "msvcrt/stdlib.h"
|
---|
31 | #include "msvcrt/string.h"
|
---|
32 |
|
---|
33 | #include "wine/debug.h"
|
---|
34 |
|
---|
35 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
---|
36 |
|
---|
37 | #else /* !__MINIVCRT__ */
|
---|
38 |
|
---|
39 | #include <winbase.h>
|
---|
40 | #include <winerror.h>
|
---|
41 |
|
---|
42 | #include "minivcrt.h"
|
---|
43 | #include "minivcrt_internal.h"
|
---|
44 |
|
---|
45 | #include <errno.h>
|
---|
46 |
|
---|
47 | #endif /* !__MINIVCRT__ */
|
---|
48 |
|
---|
49 | /* INTERNAL: Set the crt and dos errno's from the OS error given. */
|
---|
50 | void MSVCRT__set_errno(int err)
|
---|
51 | {
|
---|
52 | #ifndef __MINIVCRT__
|
---|
53 |
|
---|
54 | int *__errno = MSVCRT__errno();
|
---|
55 | unsigned long *doserrno = MSVCRT_doserrno();
|
---|
56 |
|
---|
57 | *doserrno = err;
|
---|
58 |
|
---|
59 | #define ERR_CASE(oserr) case oserr:
|
---|
60 | #define ERR_MAPS(oserr,crterr) case oserr:*__errno = MSVCRT_##crterr;break;
|
---|
61 |
|
---|
62 | #else /* !__MINIVCRT__ */
|
---|
63 |
|
---|
64 | int *__errno = _errno();
|
---|
65 |
|
---|
66 | #define ERR_CASE(oserr) case oserr:
|
---|
67 | #define ERR_MAPS(oserr,crterr) case oserr:*__errno = crterr;break;
|
---|
68 |
|
---|
69 | #endif /* !__MINIVCRT__ */
|
---|
70 |
|
---|
71 | switch(err)
|
---|
72 | {
|
---|
73 | ERR_CASE(ERROR_ACCESS_DENIED)
|
---|
74 | ERR_CASE(ERROR_NETWORK_ACCESS_DENIED)
|
---|
75 | ERR_CASE(ERROR_CANNOT_MAKE)
|
---|
76 | ERR_CASE(ERROR_SEEK_ON_DEVICE)
|
---|
77 | ERR_CASE(ERROR_LOCK_FAILED)
|
---|
78 | ERR_CASE(ERROR_FAIL_I24)
|
---|
79 | ERR_CASE(ERROR_CURRENT_DIRECTORY)
|
---|
80 | ERR_CASE(ERROR_DRIVE_LOCKED)
|
---|
81 | ERR_CASE(ERROR_NOT_LOCKED)
|
---|
82 | ERR_CASE(ERROR_INVALID_ACCESS)
|
---|
83 | ERR_MAPS(ERROR_LOCK_VIOLATION, EACCES);
|
---|
84 | ERR_CASE(ERROR_FILE_NOT_FOUND)
|
---|
85 | ERR_CASE(ERROR_NO_MORE_FILES)
|
---|
86 | ERR_CASE(ERROR_BAD_PATHNAME)
|
---|
87 | ERR_CASE(ERROR_BAD_NETPATH)
|
---|
88 | ERR_CASE(ERROR_INVALID_DRIVE)
|
---|
89 | ERR_CASE(ERROR_BAD_NET_NAME)
|
---|
90 | ERR_CASE(ERROR_FILENAME_EXCED_RANGE)
|
---|
91 | ERR_MAPS(ERROR_PATH_NOT_FOUND, ENOENT);
|
---|
92 | ERR_MAPS(ERROR_IO_DEVICE, EIO);
|
---|
93 | ERR_MAPS(ERROR_BAD_FORMAT, ENOEXEC);
|
---|
94 | ERR_MAPS(ERROR_INVALID_HANDLE, EBADF);
|
---|
95 | ERR_CASE(ERROR_OUTOFMEMORY)
|
---|
96 | ERR_CASE(ERROR_INVALID_BLOCK)
|
---|
97 | ERR_CASE(ERROR_NOT_ENOUGH_QUOTA);
|
---|
98 | ERR_MAPS(ERROR_ARENA_TRASHED, ENOMEM);
|
---|
99 | ERR_MAPS(ERROR_BUSY, EBUSY);
|
---|
100 | ERR_CASE(ERROR_ALREADY_EXISTS)
|
---|
101 | ERR_MAPS(ERROR_FILE_EXISTS, EEXIST);
|
---|
102 | ERR_MAPS(ERROR_BAD_DEVICE, ENODEV);
|
---|
103 | ERR_MAPS(ERROR_TOO_MANY_OPEN_FILES, EMFILE);
|
---|
104 | ERR_MAPS(ERROR_DISK_FULL, ENOSPC);
|
---|
105 | ERR_MAPS(ERROR_BROKEN_PIPE, EPIPE);
|
---|
106 | ERR_MAPS(ERROR_POSSIBLE_DEADLOCK, EDEADLK);
|
---|
107 | ERR_MAPS(ERROR_DIR_NOT_EMPTY, ENOTEMPTY);
|
---|
108 | ERR_MAPS(ERROR_BAD_ENVIRONMENT, E2BIG);
|
---|
109 | ERR_CASE(ERROR_WAIT_NO_CHILDREN)
|
---|
110 | ERR_MAPS(ERROR_CHILD_NOT_COMPLETE, ECHILD);
|
---|
111 | ERR_CASE(ERROR_NO_PROC_SLOTS)
|
---|
112 | ERR_CASE(ERROR_MAX_THRDS_REACHED)
|
---|
113 | ERR_MAPS(ERROR_NESTING_NOT_ALLOWED, EAGAIN);
|
---|
114 | default:
|
---|
115 | /* Remaining cases map to EINVAL */
|
---|
116 | /* FIXME: may be missing some errors above */
|
---|
117 | *__errno = MSVCRT(EINVAL);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | #ifndef __MINIVCRT__
|
---|
122 |
|
---|
123 | /*********************************************************************
|
---|
124 | * _errno (MSVCRT.@)
|
---|
125 | */
|
---|
126 | int* MSVCRT__errno(void)
|
---|
127 | {
|
---|
128 | dprintf(("MSVCRT: __errno %d",msvcrt_get_thread_data()->msv_errno));
|
---|
129 | return &msvcrt_get_thread_data()->msv_errno;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /*********************************************************************
|
---|
133 | * MSVCRT_doserrno (MSVCRT.@)
|
---|
134 | */
|
---|
135 | unsigned long* MSVCRT_doserrno(void)
|
---|
136 | {
|
---|
137 | dprintf(("MSVCRT: _doserrno %d",msvcrt_get_thread_data()->doserrno));
|
---|
138 | return &msvcrt_get_thread_data()->doserrno;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /*********************************************************************
|
---|
142 | * strerror (MSVCRT.@)
|
---|
143 | */
|
---|
144 | char* MSVCRT_strerror(int err)
|
---|
145 | {
|
---|
146 | return strerror(err); /* FIXME */
|
---|
147 | }
|
---|
148 |
|
---|
149 | /**********************************************************************
|
---|
150 | * _strerror (MSVCRT.@)
|
---|
151 | */
|
---|
152 | char* MSVCRT__strerror(const char* err)
|
---|
153 | {
|
---|
154 | static char strerrbuff[256]; /* FIXME: Per thread, nprintf */
|
---|
155 | sprintf(strerrbuff,"%s: %s\n",err,MSVCRT_strerror(msvcrt_get_thread_data()->msv_errno));
|
---|
156 | return strerrbuff;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /*********************************************************************
|
---|
160 | * perror (MSVCRT.@)
|
---|
161 | */
|
---|
162 | void MSVCRT_perror(const char* str)
|
---|
163 | {
|
---|
164 | MSVCRT__cprintf("%s: %s\n",str,MSVCRT_strerror(msvcrt_get_thread_data()->msv_errno));
|
---|
165 | }
|
---|
166 |
|
---|
167 | #endif /* !__MINIVCRT__ */
|
---|