qmgr: Merge a helper function.
[wine/multimedia.git] / dlls / msvcp71 / misc.c
blob21ca9295ea68964569bd2efa0dee0e946527e37d
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 /* ??0_Mutex@std@@QAE@XZ */
32 /* ??0_Mutex@std@@QEAA@XZ */
33 DEFINE_THISCALL_WRAPPER(mutex_ctor, 4)
34 mutex* __thiscall mutex_ctor(mutex *this)
36 CRITICAL_SECTION *cs = MSVCRT_operator_new(sizeof(*cs));
37 if(!cs) {
38 ERR("Out of memory\n");
39 throw_exception(EXCEPTION_BAD_ALLOC, NULL);
42 InitializeCriticalSection(cs);
43 cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section");
44 this->mutex = cs;
45 return this;
48 /* ??1_Mutex@std@@QAE@XZ */
49 /* ??1_Mutex@std@@QEAA@XZ */
50 DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
51 void __thiscall mutex_dtor(mutex *this)
53 ((CRITICAL_SECTION*)this->mutex)->DebugInfo->Spare[0] = 0;
54 DeleteCriticalSection(this->mutex);
55 MSVCRT_operator_delete(this->mutex);
58 /* ?_Lock@_Mutex@std@@QAEXXZ */
59 /* ?_Lock@_Mutex@std@@QEAAXXZ */
60 DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
61 void __thiscall mutex_lock(mutex *this)
63 EnterCriticalSection(this->mutex);
66 /* ?_Unlock@_Mutex@std@@QAEXXZ */
67 /* ?_Unlock@_Mutex@std@@QEAAXXZ */
68 DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
69 void __thiscall mutex_unlock(mutex *this)
71 LeaveCriticalSection(this->mutex);
74 static CRITICAL_SECTION lockit_cs[_MAX_LOCK];
76 /* ?_Lockit_ctor@_Lockit@std@@SAXH@Z */
77 static void _Lockit_init(int locktype) {
78 InitializeCriticalSection(&lockit_cs[locktype]);
79 lockit_cs[locktype].DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Lockit critical section");
82 /* ?_Lockit_dtor@_Lockit@std@@SAXH@Z */
83 static void _Lockit_free(int locktype)
85 lockit_cs[locktype].DebugInfo->Spare[0] = 0;
86 DeleteCriticalSection(&lockit_cs[locktype]);
89 void init_lockit(void) {
90 int i;
92 for(i=0; i<_MAX_LOCK; i++)
93 _Lockit_init(i);
96 void free_lockit(void) {
97 int i;
99 for(i=0; i<_MAX_LOCK; i++)
100 _Lockit_free(i);
103 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@H@Z */
104 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@H@Z */
105 static void _Lockit__Lockit_ctor_locktype(_Lockit *lockit, int locktype)
107 lockit->locktype = locktype;
108 EnterCriticalSection(&lockit_cs[locktype]);
111 /* ??0_Lockit@std@@QAE@H@Z */
112 /* ??0_Lockit@std@@QEAA@H@Z */
113 DEFINE_THISCALL_WRAPPER(_Lockit_ctor_locktype, 8)
114 _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit *this, int locktype)
116 _Lockit__Lockit_ctor_locktype(this, locktype);
117 return this;
120 /* ??0_Lockit@std@@QAE@XZ */
121 /* ??0_Lockit@std@@QEAA@XZ */
122 DEFINE_THISCALL_WRAPPER(_Lockit_ctor, 4)
123 _Lockit* __thiscall _Lockit_ctor(_Lockit *this)
125 _Lockit__Lockit_ctor_locktype(this, 0);
126 return this;
129 /* ?_Lockit_dtor@_Lockit@std@@CAXPAV12@@Z */
130 /* ?_Lockit_dtor@_Lockit@std@@CAXPEAV12@@Z */
131 static void _Lockit__Lockit_dtor(_Lockit *lockit)
133 LeaveCriticalSection(&lockit_cs[lockit->locktype]);
136 /* ??1_Lockit@std@@QAE@XZ */
137 /* ??1_Lockit@std@@QEAA@XZ */
138 DEFINE_THISCALL_WRAPPER(_Lockit_dtor, 4)
139 void __thiscall _Lockit_dtor(_Lockit *this)
141 _Lockit__Lockit_dtor(this);
144 /* wctype */
145 unsigned short __cdecl wctype(const char *property)
147 static const struct {
148 const char *name;
149 unsigned short mask;
150 } properties[] = {
151 { "alnum", _DIGIT|_ALPHA },
152 { "alpha", _ALPHA },
153 { "cntrl", _CONTROL },
154 { "digit", _DIGIT },
155 { "graph", _DIGIT|_PUNCT|_ALPHA },
156 { "lower", _LOWER },
157 { "print", _DIGIT|_PUNCT|_BLANK|_ALPHA },
158 { "punct", _PUNCT },
159 { "space", _SPACE },
160 { "upper", _UPPER },
161 { "xdigit", _HEX }
163 int i;
165 for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++)
166 if(!strcmp(property, properties[i].name))
167 return properties[i].mask;
169 return 0;
172 typedef void (__cdecl *MSVCP_new_handler_func)(void);
173 static MSVCP_new_handler_func MSVCP_new_handler;
174 static int __cdecl new_handler_wrapper(MSVCP_size_t unused)
176 MSVCP_new_handler();
177 return 1;
180 /* ?set_new_handler@std@@YAP6AXXZP6AXXZ@Z */
181 MSVCP_new_handler_func __cdecl set_new_handler(MSVCP_new_handler_func new_handler)
183 MSVCP_new_handler_func old_handler = MSVCP_new_handler;
185 TRACE("%p\n", new_handler);
187 MSVCP_new_handler = new_handler;
188 MSVCRT_set_new_handler(new_handler ? new_handler_wrapper : NULL);
189 return old_handler;