msvcp: Sync istream<>::peek implementations.
[wine.git] / dlls / msvcp71 / misc.c
blob8615a51aecb9689073a08f35cedb1222fcf995f2
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 this->mutex = CreateMutexW(NULL, FALSE, NULL);
37 return this;
40 /* ??1_Mutex@std@@QAE@XZ */
41 /* ??1_Mutex@std@@QEAA@XZ */
42 DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
43 void __thiscall mutex_dtor(mutex *this)
45 CloseHandle(this->mutex);
48 /* ?_Lock@_Mutex@std@@QAEXXZ */
49 /* ?_Lock@_Mutex@std@@QEAAXXZ */
50 DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
51 void __thiscall mutex_lock(mutex *this)
53 WaitForSingleObject(this->mutex, INFINITE);
56 /* ?_Unlock@_Mutex@std@@QAEXXZ */
57 /* ?_Unlock@_Mutex@std@@QEAAXXZ */
58 DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
59 void __thiscall mutex_unlock(mutex *this)
61 ReleaseMutex(this->mutex);
64 static CRITICAL_SECTION lockit_cs[_MAX_LOCK];
66 /* ?_Lockit_ctor@_Lockit@std@@SAXH@Z */
67 static void _Lockit_init(int locktype) {
68 InitializeCriticalSection(&lockit_cs[locktype]);
69 lockit_cs[locktype].DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Lockit critical section");
72 /* ?_Lockit_dtor@_Lockit@std@@SAXH@Z */
73 static void _Lockit_free(int locktype)
75 lockit_cs[locktype].DebugInfo->Spare[0] = 0;
76 DeleteCriticalSection(&lockit_cs[locktype]);
79 void init_lockit(void) {
80 int i;
82 for(i=0; i<_MAX_LOCK; i++)
83 _Lockit_init(i);
86 void free_lockit(void) {
87 int i;
89 for(i=0; i<_MAX_LOCK; i++)
90 _Lockit_free(i);
93 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@H@Z */
94 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@H@Z */
95 static void _Lockit__Lockit_ctor_locktype(_Lockit *lockit, int locktype)
97 lockit->locktype = locktype;
98 EnterCriticalSection(&lockit_cs[locktype]);
101 /* ??0_Lockit@std@@QAE@H@Z */
102 /* ??0_Lockit@std@@QEAA@H@Z */
103 DEFINE_THISCALL_WRAPPER(_Lockit_ctor_locktype, 8)
104 _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit *this, int locktype)
106 _Lockit__Lockit_ctor_locktype(this, locktype);
107 return this;
110 /* ??0_Lockit@std@@QAE@XZ */
111 /* ??0_Lockit@std@@QEAA@XZ */
112 DEFINE_THISCALL_WRAPPER(_Lockit_ctor, 4)
113 _Lockit* __thiscall _Lockit_ctor(_Lockit *this)
115 _Lockit__Lockit_ctor_locktype(this, 0);
116 return this;
119 /* ?_Lockit_dtor@_Lockit@std@@CAXPAV12@@Z */
120 /* ?_Lockit_dtor@_Lockit@std@@CAXPEAV12@@Z */
121 static void _Lockit__Lockit_dtor(_Lockit *lockit)
123 LeaveCriticalSection(&lockit_cs[lockit->locktype]);
126 /* ??1_Lockit@std@@QAE@XZ */
127 /* ??1_Lockit@std@@QEAA@XZ */
128 DEFINE_THISCALL_WRAPPER(_Lockit_dtor, 4)
129 void __thiscall _Lockit_dtor(_Lockit *this)
131 _Lockit__Lockit_dtor(this);
134 /* wctype */
135 unsigned short __cdecl wctype(const char *property)
137 static const struct {
138 const char *name;
139 unsigned short mask;
140 } properties[] = {
141 { "alnum", _DIGIT|_ALPHA },
142 { "alpha", _ALPHA },
143 { "cntrl", _CONTROL },
144 { "digit", _DIGIT },
145 { "graph", _DIGIT|_PUNCT|_ALPHA },
146 { "lower", _LOWER },
147 { "print", _DIGIT|_PUNCT|_BLANK|_ALPHA },
148 { "punct", _PUNCT },
149 { "space", _SPACE },
150 { "upper", _UPPER },
151 { "xdigit", _HEX }
153 int i;
155 for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++)
156 if(!strcmp(property, properties[i].name))
157 return properties[i].mask;
159 return 0;
162 typedef void (__cdecl *MSVCP_new_handler_func)(void);
163 static MSVCP_new_handler_func MSVCP_new_handler;
164 static int __cdecl new_handler_wrapper(MSVCP_size_t unused)
166 MSVCP_new_handler();
167 return 1;
170 /* ?set_new_handler@std@@YAP6AXXZP6AXXZ@Z */
171 MSVCP_new_handler_func __cdecl set_new_handler(MSVCP_new_handler_func new_handler)
173 MSVCP_new_handler_func old_handler = MSVCP_new_handler;
175 TRACE("%p\n", new_handler);
177 MSVCP_new_handler = new_handler;
178 MSVCRT_set_new_handler(new_handler ? new_handler_wrapper : NULL);
179 return old_handler;