netstat: Fix compilation on systems that don't support nameless unions.
[wine.git] / dlls / msvcp100 / misc.c
blob55a19ee9d87f28212740d2100f07138d0acf63ee
1 /*
2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
22 #include <limits.h>
24 #include "msvcp.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
31 struct __Container_proxy;
33 typedef struct {
34 struct __Container_proxy *proxy;
35 } _Container_base12;
37 typedef struct __Iterator_base12 {
38 struct __Container_proxy *proxy;
39 struct __Iterator_base12 *next;
40 } _Iterator_base12;
42 typedef struct __Container_proxy {
43 const _Container_base12 *cont;
44 _Iterator_base12 *head;
45 } _Container_proxy;
47 /* ??0_Mutex@std@@QAE@XZ */
48 /* ??0_Mutex@std@@QEAA@XZ */
49 DEFINE_THISCALL_WRAPPER(mutex_ctor, 4)
50 mutex* __thiscall mutex_ctor(mutex *this)
52 CRITICAL_SECTION *cs = MSVCRT_operator_new(sizeof(*cs));
53 if(!cs) {
54 ERR("Out of memory\n");
55 throw_exception(EXCEPTION_BAD_ALLOC, NULL);
58 InitializeCriticalSection(cs);
59 cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section");
60 this->mutex = cs;
61 return this;
64 /* ??1_Mutex@std@@QAE@XZ */
65 /* ??1_Mutex@std@@QEAA@XZ */
66 DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
67 void __thiscall mutex_dtor(mutex *this)
69 ((CRITICAL_SECTION*)this->mutex)->DebugInfo->Spare[0] = 0;
70 DeleteCriticalSection(this->mutex);
71 MSVCRT_operator_delete(this->mutex);
74 /* ?_Lock@_Mutex@std@@QAEXXZ */
75 /* ?_Lock@_Mutex@std@@QEAAXXZ */
76 DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
77 void __thiscall mutex_lock(mutex *this)
79 EnterCriticalSection(this->mutex);
82 /* ?_Unlock@_Mutex@std@@QAEXXZ */
83 /* ?_Unlock@_Mutex@std@@QEAAXXZ */
84 DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
85 void __thiscall mutex_unlock(mutex *this)
87 LeaveCriticalSection(this->mutex);
90 /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */
91 /* ?_Mutex_Lock@_Mutex@std@@CAXPEAV12@@Z */
92 void CDECL mutex_mutex_lock(mutex *m)
94 mutex_lock(m);
97 /* ?_Mutex_Unlock@_Mutex@std@@CAXPAV12@@Z */
98 /* ?_Mutex_Unlock@_Mutex@std@@CAXPEAV12@@Z */
99 void CDECL mutex_mutex_unlock(mutex *m)
101 mutex_unlock(m);
104 /* ?_Mutex_ctor@_Mutex@std@@CAXPAV12@@Z */
105 /* ?_Mutex_ctor@_Mutex@std@@CAXPEAV12@@Z */
106 void CDECL mutex_mutex_ctor(mutex *m)
108 mutex_ctor(m);
111 /* ?_Mutex_dtor@_Mutex@std@@CAXPAV12@@Z */
112 /* ?_Mutex_dtor@_Mutex@std@@CAXPEAV12@@Z */
113 void CDECL mutex_mutex_dtor(mutex *m)
115 mutex_dtor(m);
118 static CRITICAL_SECTION lockit_cs[_MAX_LOCK];
120 /* ?_Lockit_ctor@_Lockit@std@@SAXH@Z */
121 void __cdecl _Lockit_init(int locktype) {
122 InitializeCriticalSection(&lockit_cs[locktype]);
123 lockit_cs[locktype].DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Lockit critical section");
126 /* ?_Lockit_dtor@_Lockit@std@@SAXH@Z */
127 void __cdecl _Lockit_free(int locktype)
129 lockit_cs[locktype].DebugInfo->Spare[0] = 0;
130 DeleteCriticalSection(&lockit_cs[locktype]);
133 void init_lockit(void) {
134 int i;
136 for(i=0; i<_MAX_LOCK; i++)
137 _Lockit_init(i);
140 void free_lockit(void) {
141 int i;
143 for(i=0; i<_MAX_LOCK; i++)
144 _Lockit_free(i);
147 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@H@Z */
148 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@H@Z */
149 void __cdecl _Lockit__Lockit_ctor_locktype(_Lockit *lockit, int locktype)
151 lockit->locktype = locktype;
152 EnterCriticalSection(&lockit_cs[locktype]);
155 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@@Z */
156 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@@Z */
157 void __cdecl _Lockit__Lockit_ctor(_Lockit *lockit)
159 _Lockit__Lockit_ctor_locktype(lockit, 0);
162 /* ??0_Lockit@std@@QAE@H@Z */
163 /* ??0_Lockit@std@@QEAA@H@Z */
164 DEFINE_THISCALL_WRAPPER(_Lockit_ctor_locktype, 8)
165 _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit *this, int locktype)
167 _Lockit__Lockit_ctor_locktype(this, locktype);
168 return this;
171 /* ??0_Lockit@std@@QAE@XZ */
172 /* ??0_Lockit@std@@QEAA@XZ */
173 DEFINE_THISCALL_WRAPPER(_Lockit_ctor, 4)
174 _Lockit* __thiscall _Lockit_ctor(_Lockit *this)
176 _Lockit__Lockit_ctor_locktype(this, 0);
177 return this;
180 /* ?_Lockit_dtor@_Lockit@std@@CAXPAV12@@Z */
181 /* ?_Lockit_dtor@_Lockit@std@@CAXPEAV12@@Z */
182 void __cdecl _Lockit__Lockit_dtor(_Lockit *lockit)
184 LeaveCriticalSection(&lockit_cs[lockit->locktype]);
187 /* ??1_Lockit@std@@QAE@XZ */
188 /* ??1_Lockit@std@@QEAA@XZ */
189 DEFINE_THISCALL_WRAPPER(_Lockit_dtor, 4)
190 void __thiscall _Lockit_dtor(_Lockit *this)
192 _Lockit__Lockit_dtor(this);
195 /* wctype */
196 unsigned short __cdecl wctype(const char *property)
198 static const struct {
199 const char *name;
200 unsigned short mask;
201 } properties[] = {
202 { "alnum", _DIGIT|_ALPHA },
203 { "alpha", _ALPHA },
204 { "cntrl", _CONTROL },
205 { "digit", _DIGIT },
206 { "graph", _DIGIT|_PUNCT|_ALPHA },
207 { "lower", _LOWER },
208 { "print", _DIGIT|_PUNCT|_BLANK|_ALPHA },
209 { "punct", _PUNCT },
210 { "space", _SPACE },
211 { "upper", _UPPER },
212 { "xdigit", _HEX }
214 int i;
216 for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++)
217 if(!strcmp(property, properties[i].name))
218 return properties[i].mask;
220 return 0;
223 typedef void (__cdecl *MSVCP_new_handler_func)(void);
224 static MSVCP_new_handler_func MSVCP_new_handler;
225 static int __cdecl new_handler_wrapper(MSVCP_size_t unused)
227 MSVCP_new_handler();
228 return 1;
231 /* ?set_new_handler@std@@YAP6AXXZP6AXXZ@Z */
232 MSVCP_new_handler_func __cdecl set_new_handler(MSVCP_new_handler_func new_handler)
234 MSVCP_new_handler_func old_handler = MSVCP_new_handler;
236 TRACE("%p\n", new_handler);
238 MSVCP_new_handler = new_handler;
239 MSVCRT_set_new_handler(new_handler ? new_handler_wrapper : NULL);
240 return old_handler;
243 /* ?set_new_handler@std@@YAP6AXXZH@Z */
244 MSVCP_new_handler_func __cdecl set_new_handler_reset(int unused)
246 return set_new_handler(NULL);
249 /* _Container_base0 is used by apps compiled without iterator checking
250 * (i.e. with _ITERATOR_DEBUG_LEVEL=0 ).
251 * It provides empty versions of methods used by visual c++'s stl's
252 * iterator checking.
253 * msvcr100 has to provide them in case apps are compiled with /Od
254 * or the optimizer fails to inline those (empty) calls.
257 /* ?_Orphan_all@_Container_base0@std@@QAEXXZ */
258 /* ?_Orphan_all@_Container_base0@std@@QEAAXXZ */
259 DEFINE_THISCALL_WRAPPER(Container_base0_Orphan_all, 4)
260 void __thiscall Container_base0_Orphan_all(void *this)
264 /* ?_Swap_all@_Container_base0@std@@QAEXAAU12@@Z */
265 /* ?_Swap_all@_Container_base0@std@@QEAAXAEAU12@@Z */
266 DEFINE_THISCALL_WRAPPER(Container_base0_Swap_all, 8)
267 void __thiscall Container_base0_Swap_all(void *this, void *that)
271 /* ??4_Container_base0@std@@QAEAAU01@ABU01@@Z */
272 /* ??4_Container_base0@std@@QEAAAEAU01@AEBU01@@Z */
273 DEFINE_THISCALL_WRAPPER(Container_base0_op_assign, 8)
274 void* __thiscall Container_base0_op_assign(void *this, const void *that)
276 return this;
279 /* ??0_Container_base12@std@@QAE@ABU01@@Z */
280 /* ??0_Container_base12@std@@QEAA@AEBU01@@Z */
281 DEFINE_THISCALL_WRAPPER(_Container_base12_copy_ctor, 8)
282 _Container_base12* __thiscall _Container_base12_copy_ctor(
283 _Container_base12 *this, _Container_base12 *that)
285 this->proxy = NULL;
286 return this;
289 /* ??0_Container_base12@std@@QAE@XZ */
290 /* ??0_Container_base12@std@@QEAA@XZ */
291 DEFINE_THISCALL_WRAPPER(_Container_base12_ctor, 4)
292 _Container_base12* __thiscall _Container_base12_ctor(_Container_base12 *this)
294 this->proxy = NULL;
295 return this;
298 /* ??1_Container_base12@std@@QAE@XZ */
299 /* ??1_Container_base12@std@@QEAA@XZ */
300 DEFINE_THISCALL_WRAPPER(_Container_base12_dtor, 4)
301 void __thiscall _Container_base12_dtor(_Container_base12 *this)
305 /* ??4_Container_base12@std@@QAEAAU01@ABU01@@Z */
306 /* ??4_Container_base12@std@@QEAAAEAU01@AEBU01@@ */
307 DEFINE_THISCALL_WRAPPER(_Container_base12_op_assign, 8)
308 _Container_base12* __thiscall _Container_base12_op_assign(
309 _Container_base12 *this, const _Container_base12 *that)
311 return this;
314 /* ?_Getpfirst@_Container_base12@std@@QBEPAPAU_Iterator_base12@2@XZ */
315 /* ?_Getpfirst@_Container_base12@std@@QEBAPEAPEAU_Iterator_base12@2@XZ */
316 DEFINE_THISCALL_WRAPPER(_Container_base12__Getpfirst, 4)
317 _Iterator_base12** __thiscall _Container_base12__Getpfirst(_Container_base12 *this)
319 return this->proxy ? &this->proxy->head : NULL;
322 /* ?_Orphan_all@_Container_base12@std@@QAEXXZ */
323 /* ?_Orphan_all@_Container_base12@std@@QEAAXXZ */
324 DEFINE_THISCALL_WRAPPER(_Container_base12__Orphan_all, 4)
325 void __thiscall _Container_base12__Orphan_all(_Container_base12 *this)
329 /* ?_Swap_all@_Container_base12@std@@QAEXAAU12@@Z */
330 /* ?_Swap_all@_Container_base12@std@@QEAAXAEAU12@@Z */
331 DEFINE_THISCALL_WRAPPER(_Container_base12__Swap_all, 8)
332 void __thiscall _Container_base12__Swap_all(
333 _Container_base12 *this, _Container_base12 *that)
335 _Container_proxy *tmp;
337 tmp = this->proxy;
338 this->proxy = that->proxy;
339 that->proxy = tmp;
341 if(this->proxy)
342 this->proxy->cont = this;
343 if(that->proxy)
344 that->proxy->cont = that;