uiautomationcore: Implement UiaGetPropertyValue.
[wine.git] / dlls / msvcirt / msvcirt.c
blob35f532425d32bbf06115ea3fb373ccda2e01ee9c
1 /*
2 * Copyright (C) 2007 Alexandre Julliard
3 * Copyright (C) 2015-2016 Iván Matellanes
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <errno.h>
22 #include <fcntl.h>
23 #include <float.h>
24 #include <io.h>
25 #include <limits.h>
26 #include <share.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <sys/stat.h>
31 #include "msvcirt.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msvcirt);
38 #define RESERVE_SIZE 512
39 #define STATEBUF_SIZE 8
41 void* (__cdecl *operator_new)(SIZE_T);
42 void (__cdecl *operator_delete)(void*);
44 /* ?sh_none@filebuf@@2HB */
45 const int filebuf_sh_none = 0x800;
46 /* ?sh_read@filebuf@@2HB */
47 const int filebuf_sh_read = 0xa00;
48 /* ?sh_write@filebuf@@2HB */
49 const int filebuf_sh_write = 0xc00;
50 /* ?openprot@filebuf@@2HB */
51 const int filebuf_openprot = 420;
52 /* ?binary@filebuf@@2HB */
53 const int filebuf_binary = _O_BINARY;
54 /* ?text@filebuf@@2HB */
55 const int filebuf_text = _O_TEXT;
57 /* ?adjustfield@ios@@2JB */
58 const LONG ios_adjustfield = FLAGS_left | FLAGS_right | FLAGS_internal;
59 /* ?basefield@ios@@2JB */
60 const LONG ios_basefield = FLAGS_dec | FLAGS_oct | FLAGS_hex;
61 /* ?floatfield@ios@@2JB */
62 const LONG ios_floatfield = FLAGS_scientific | FLAGS_fixed;
63 /* ?fLockcInit@ios@@0HA */
64 int ios_fLockcInit = 0;
65 /* ?sunk_with_stdio@ios@@0HA */
66 int ios_sunk_with_stdio = 0;
67 /* ?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A */
68 extern CRITICAL_SECTION ios_static_lock;
69 CRITICAL_SECTION_DEBUG ios_static_lock_debug =
71 0, 0, &ios_static_lock,
72 { &ios_static_lock_debug.ProcessLocksList, &ios_static_lock_debug.ProcessLocksList },
73 0, 0, { (DWORD_PTR)(__FILE__ ": ios_static_lock") }
75 CRITICAL_SECTION ios_static_lock = { &ios_static_lock_debug, -1, 0, 0, 0, 0 };
76 /* ?x_maxbit@ios@@0JA */
77 LONG ios_maxbit = 0x8000;
78 /* ?x_curindex@ios@@0HA */
79 int ios_curindex = -1;
80 /* ?x_statebuf@ios@@0PAJA */
81 LONG ios_statebuf[STATEBUF_SIZE] = {0};
83 /* class streambuf */
84 typedef struct {
85 const vtable_ptr *vtable;
86 int allocated;
87 int unbuffered;
88 int stored_char;
89 char *base;
90 char *ebuf;
91 char *pbase;
92 char *pptr;
93 char *epptr;
94 char *eback;
95 char *gptr;
96 char *egptr;
97 int do_lock;
98 CRITICAL_SECTION lock;
99 } streambuf;
101 void __thiscall streambuf_setb(streambuf*, char*, char*, int);
102 streambuf* __thiscall streambuf_setbuf(streambuf*, char*, int);
103 void __thiscall streambuf_setg(streambuf*, char*, char*, char*);
104 void __thiscall streambuf_setp(streambuf*, char*, char*);
106 /* class filebuf */
107 typedef struct {
108 streambuf base;
109 filedesc fd;
110 int close;
111 } filebuf;
113 filebuf* __thiscall filebuf_close(filebuf*);
115 /* class strstreambuf */
116 typedef struct {
117 streambuf base;
118 int dynamic;
119 int increase;
120 int unknown;
121 int constant;
122 allocFunction f_alloc;
123 freeFunction f_free;
124 } strstreambuf;
126 /* class stdiobuf */
127 typedef struct {
128 streambuf base;
129 FILE *file;
130 } stdiobuf;
132 /* class ios */
133 struct _ostream;
134 typedef struct {
135 const vtable_ptr *vtable;
136 streambuf *sb;
137 ios_io_state state;
138 int special[4];
139 int delbuf;
140 struct _ostream *tie;
141 ios_flags flags;
142 int precision;
143 char fill;
144 int width;
145 int do_lock;
146 CRITICAL_SECTION lock;
147 } ios;
149 ios* __thiscall ios_assign(ios*, const ios*);
150 int __thiscall ios_fail(const ios*);
151 void __cdecl ios_lock(ios*);
152 void __cdecl ios_lockc(void);
153 LONG __thiscall ios_setf_mask(ios*, LONG, LONG);
154 void __cdecl ios_unlock(ios*);
155 void __cdecl ios_unlockc(void);
157 /* class ostream */
158 typedef struct _ostream {
159 const int *vbtable;
160 int unknown;
161 } ostream;
163 /* class istream */
164 typedef struct {
165 const int *vbtable;
166 int extract_delim;
167 int count;
168 } istream;
170 /* class iostream */
171 typedef struct {
172 istream base1;
173 ostream base2;
174 } iostream;
176 /* ??_7streambuf@@6B@ */
177 extern const vtable_ptr streambuf_vtable;
178 /* ??_7filebuf@@6B@ */
179 extern const vtable_ptr filebuf_vtable;
180 /* ??_7strstreambuf@@6B@ */
181 extern const vtable_ptr strstreambuf_vtable;
182 /* ??_7stdiobuf@@6B@ */
183 extern const vtable_ptr stdiobuf_vtable;
184 /* ??_7ios@@6B@ */
185 extern const vtable_ptr ios_vtable;
186 /* ??_7ostream@@6B@ */
187 extern const vtable_ptr ostream_vtable;
188 /* ??_7ostream_withassign@@6B@ */
189 extern const vtable_ptr ostream_withassign_vtable;
190 /* ??_7ostrstream@@6B@ */
191 extern const vtable_ptr ostrstream_vtable;
192 /* ??_7ofstream@@6B@ */
193 extern const vtable_ptr ofstream_vtable;
194 /* ??_7istream@@6B@ */
195 extern const vtable_ptr istream_vtable;
196 /* ??_7istream_withassign@@6B@ */
197 extern const vtable_ptr istream_withassign_vtable;
198 /* ??_7istrstream@@6B@ */
199 extern const vtable_ptr istrstream_vtable;
200 /* ??_7ifstream@@6B@ */
201 extern const vtable_ptr ifstream_vtable;
202 /* ??_7iostream@@6B@ */
203 extern const vtable_ptr iostream_vtable;
204 /* ??_7strstream@@6B@ */
205 extern const vtable_ptr strstream_vtable;
206 /* ??_7stdiostream@@6B@ */
207 extern const vtable_ptr stdiostream_vtable;
208 /* ??_7fstream@@6B@ */
209 extern const vtable_ptr fstream_vtable;
211 __ASM_BLOCK_BEGIN(vtables)
212 __ASM_VTABLE(streambuf,
213 VTABLE_ADD_FUNC(streambuf_vector_dtor)
214 VTABLE_ADD_FUNC(streambuf_sync)
215 VTABLE_ADD_FUNC(streambuf_setbuf)
216 VTABLE_ADD_FUNC(streambuf_seekoff)
217 VTABLE_ADD_FUNC(streambuf_seekpos)
218 VTABLE_ADD_FUNC(streambuf_xsputn)
219 VTABLE_ADD_FUNC(streambuf_xsgetn)
220 VTABLE_ADD_FUNC(streambuf_overflow)
221 VTABLE_ADD_FUNC(streambuf_underflow)
222 VTABLE_ADD_FUNC(streambuf_pbackfail)
223 VTABLE_ADD_FUNC(streambuf_doallocate));
224 __ASM_VTABLE(filebuf,
225 VTABLE_ADD_FUNC(filebuf_vector_dtor)
226 VTABLE_ADD_FUNC(filebuf_sync)
227 VTABLE_ADD_FUNC(filebuf_setbuf)
228 VTABLE_ADD_FUNC(filebuf_seekoff)
229 VTABLE_ADD_FUNC(streambuf_seekpos)
230 VTABLE_ADD_FUNC(streambuf_xsputn)
231 VTABLE_ADD_FUNC(streambuf_xsgetn)
232 VTABLE_ADD_FUNC(filebuf_overflow)
233 VTABLE_ADD_FUNC(filebuf_underflow)
234 VTABLE_ADD_FUNC(streambuf_pbackfail)
235 VTABLE_ADD_FUNC(streambuf_doallocate));
236 __ASM_VTABLE(strstreambuf,
237 VTABLE_ADD_FUNC(strstreambuf_vector_dtor)
238 VTABLE_ADD_FUNC(strstreambuf_sync)
239 VTABLE_ADD_FUNC(strstreambuf_setbuf)
240 VTABLE_ADD_FUNC(strstreambuf_seekoff)
241 VTABLE_ADD_FUNC(streambuf_seekpos)
242 VTABLE_ADD_FUNC(streambuf_xsputn)
243 VTABLE_ADD_FUNC(streambuf_xsgetn)
244 VTABLE_ADD_FUNC(strstreambuf_overflow)
245 VTABLE_ADD_FUNC(strstreambuf_underflow)
246 VTABLE_ADD_FUNC(streambuf_pbackfail)
247 VTABLE_ADD_FUNC(strstreambuf_doallocate));
248 __ASM_VTABLE(stdiobuf,
249 VTABLE_ADD_FUNC(stdiobuf_vector_dtor)
250 VTABLE_ADD_FUNC(stdiobuf_sync)
251 VTABLE_ADD_FUNC(streambuf_setbuf)
252 VTABLE_ADD_FUNC(stdiobuf_seekoff)
253 VTABLE_ADD_FUNC(streambuf_seekpos)
254 VTABLE_ADD_FUNC(streambuf_xsputn)
255 VTABLE_ADD_FUNC(streambuf_xsgetn)
256 VTABLE_ADD_FUNC(stdiobuf_overflow)
257 VTABLE_ADD_FUNC(stdiobuf_underflow)
258 VTABLE_ADD_FUNC(stdiobuf_pbackfail)
259 VTABLE_ADD_FUNC(streambuf_doallocate));
260 __ASM_VTABLE(ios,
261 VTABLE_ADD_FUNC(ios_vector_dtor));
262 __ASM_VTABLE(ostream,
263 VTABLE_ADD_FUNC(ostream_vector_dtor));
264 __ASM_VTABLE(ostream_withassign,
265 VTABLE_ADD_FUNC(ostream_vector_dtor));
266 __ASM_VTABLE(ostrstream,
267 VTABLE_ADD_FUNC(ostream_vector_dtor));
268 __ASM_VTABLE(ofstream,
269 VTABLE_ADD_FUNC(ostream_vector_dtor));
270 __ASM_VTABLE(istream,
271 VTABLE_ADD_FUNC(istream_vector_dtor));
272 __ASM_VTABLE(istream_withassign,
273 VTABLE_ADD_FUNC(istream_vector_dtor));
274 __ASM_VTABLE(istrstream,
275 VTABLE_ADD_FUNC(istream_vector_dtor));
276 __ASM_VTABLE(ifstream,
277 VTABLE_ADD_FUNC(istream_vector_dtor));
278 __ASM_VTABLE(iostream,
279 VTABLE_ADD_FUNC(iostream_vector_dtor));
280 __ASM_VTABLE(strstream,
281 VTABLE_ADD_FUNC(iostream_vector_dtor));
282 __ASM_VTABLE(stdiostream,
283 VTABLE_ADD_FUNC(iostream_vector_dtor));
284 __ASM_VTABLE(fstream,
285 VTABLE_ADD_FUNC(iostream_vector_dtor));
286 __ASM_BLOCK_END
288 #define ALIGNED_SIZE(size, alignment) (((size)+((alignment)-1))/(alignment)*(alignment))
289 #define VBTABLE_ENTRY(class, offset, vbase) ALIGNED_SIZE(sizeof(class), TYPE_ALIGNMENT(vbase))-offset
291 /* ??_8ostream@@7B@ */
292 /* ??_8ostream_withassign@@7B@ */
293 /* ??_8ostrstream@@7B@ */
294 /* ??_8ofstream@@7B@ */
295 const int ostream_vbtable[] = {0, VBTABLE_ENTRY(ostream, FIELD_OFFSET(ostream, vbtable), ios)};
296 /* ??_8istream@@7B@ */
297 /* ??_8istream_withassign@@7B@ */
298 /* ??_8istrstream@@7B@ */
299 /* ??_8ifstream@@7B@ */
300 const int istream_vbtable[] = {0, VBTABLE_ENTRY(istream, FIELD_OFFSET(istream, vbtable), ios)};
301 /* ??_8iostream@@7Bistream@@@ */
302 /* ??_8stdiostream@@7Bistream@@@ */
303 /* ??_8strstream@@7Bistream@@@ */
304 const int iostream_vbtable_istream[] = {0, VBTABLE_ENTRY(iostream, FIELD_OFFSET(iostream, base1), ios)};
305 /* ??_8iostream@@7Bostream@@@ */
306 /* ??_8stdiostream@@7Bostream@@@ */
307 /* ??_8strstream@@7Bostream@@@ */
308 const int iostream_vbtable_ostream[] = {0, VBTABLE_ENTRY(iostream, FIELD_OFFSET(iostream, base2), ios)};
310 DEFINE_RTTI_DATA0(streambuf, 0, ".?AVstreambuf@@")
311 DEFINE_RTTI_DATA1(filebuf, 0, &streambuf_rtti_base_descriptor, ".?AVfilebuf@@")
312 DEFINE_RTTI_DATA1(strstreambuf, 0, &streambuf_rtti_base_descriptor, ".?AVstrstreambuf@@")
313 DEFINE_RTTI_DATA1(stdiobuf, 0, &streambuf_rtti_base_descriptor, ".?AVstdiobuf@@")
314 DEFINE_RTTI_DATA0(ios, 0, ".?AVios@@")
315 DEFINE_RTTI_DATA1(ostream, sizeof(ostream), &ios_rtti_base_descriptor, ".?AVostream@@")
316 DEFINE_RTTI_DATA2(ostream_withassign, sizeof(ostream),
317 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVostream_withassign@@")
318 DEFINE_RTTI_DATA2(ostrstream, sizeof(ostream),
319 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVostrstream@@")
320 DEFINE_RTTI_DATA2(ofstream, sizeof(ostream),
321 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVofstream@@")
322 DEFINE_RTTI_DATA1(istream, sizeof(istream), &ios_rtti_base_descriptor, ".?AVistream@@")
323 DEFINE_RTTI_DATA2(istream_withassign, sizeof(istream),
324 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVistream_withassign@@")
325 DEFINE_RTTI_DATA2(istrstream, sizeof(istream),
326 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVistrstream@@")
327 DEFINE_RTTI_DATA2(ifstream, sizeof(istream),
328 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVifstream@@")
329 DEFINE_RTTI_DATA4(iostream, sizeof(iostream),
330 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor,
331 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AViostream@@")
332 DEFINE_RTTI_DATA5(strstream, sizeof(iostream), &iostream_rtti_base_descriptor,
333 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor,
334 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVstrstream@@")
335 DEFINE_RTTI_DATA5(stdiostream, sizeof(iostream), &iostream_rtti_base_descriptor,
336 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor,
337 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVstdiostream@@")
338 DEFINE_RTTI_DATA5(fstream, sizeof(iostream), &iostream_rtti_base_descriptor,
339 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor,
340 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVfstream@@")
342 /* ?cin@@3Vistream_withassign@@A */
343 struct {
344 istream is;
345 ios vbase;
346 } cin = { { 0 } };
348 /* ?cout@@3Vostream_withassign@@A */
349 /* ?cerr@@3Vostream_withassign@@A */
350 /* ?clog@@3Vostream_withassign@@A */
351 struct {
352 ostream os;
353 ios vbase;
354 } cout = { { 0 } }, cerr = { { 0 } }, MSVCP_clog = { { 0 } };
357 /* ??0streambuf@@IAE@PADH@Z */
358 /* ??0streambuf@@IEAA@PEADH@Z */
359 DEFINE_THISCALL_WRAPPER(streambuf_reserve_ctor, 12)
360 streambuf* __thiscall streambuf_reserve_ctor(streambuf *this, char *buffer, int length)
362 TRACE("(%p %p %d)\n", this, buffer, length);
363 this->vtable = &streambuf_vtable;
364 this->allocated = 0;
365 this->stored_char = EOF;
366 this->do_lock = -1;
367 this->base = NULL;
368 streambuf_setbuf(this, buffer, length);
369 streambuf_setg(this, NULL, NULL, NULL);
370 streambuf_setp(this, NULL, NULL);
371 InitializeCriticalSection(&this->lock);
372 return this;
375 /* ??0streambuf@@IAE@XZ */
376 /* ??0streambuf@@IEAA@XZ */
377 DEFINE_THISCALL_WRAPPER(streambuf_ctor, 4)
378 streambuf* __thiscall streambuf_ctor(streambuf *this)
380 streambuf_reserve_ctor(this, NULL, 0);
381 this->unbuffered = 0;
382 return this;
385 /* ??0streambuf@@QAE@ABV0@@Z */
386 /* ??0streambuf@@QEAA@AEBV0@@Z */
387 DEFINE_THISCALL_WRAPPER(streambuf_copy_ctor, 8)
388 streambuf* __thiscall streambuf_copy_ctor(streambuf *this, const streambuf *copy)
390 TRACE("(%p %p)\n", this, copy);
391 *this = *copy;
392 this->vtable = &streambuf_vtable;
393 return this;
396 /* ??1streambuf@@UAE@XZ */
397 /* ??1streambuf@@UEAA@XZ */
398 DEFINE_THISCALL_WRAPPER(streambuf_dtor, 4)
399 void __thiscall streambuf_dtor(streambuf *this)
401 TRACE("(%p)\n", this);
402 if (this->allocated)
403 operator_delete(this->base);
404 DeleteCriticalSection(&this->lock);
407 /* ??4streambuf@@QAEAAV0@ABV0@@Z */
408 /* ??4streambuf@@QEAAAEAV0@AEBV0@@Z */
409 DEFINE_THISCALL_WRAPPER(streambuf_assign, 8)
410 streambuf* __thiscall streambuf_assign(streambuf *this, const streambuf *rhs)
412 streambuf_dtor(this);
413 return streambuf_copy_ctor(this, rhs);
416 /* ??_Estreambuf@@UAEPAXI@Z */
417 DEFINE_THISCALL_WRAPPER(streambuf_vector_dtor, 8)
418 #define call_streambuf_vector_dtor(this, flags) CALL_VTBL_FUNC(this, 0,\
419 streambuf*, (streambuf*, unsigned int), (this, flags))
420 streambuf* __thiscall streambuf_vector_dtor(streambuf *this, unsigned int flags)
422 TRACE("(%p %x)\n", this, flags);
423 if (flags & 2) {
424 /* we have an array, with the number of elements stored before the first object */
425 INT_PTR i, *ptr = (INT_PTR *)this-1;
427 for (i = *ptr-1; i >= 0; i--)
428 streambuf_dtor(this+i);
429 operator_delete(ptr);
430 } else {
431 streambuf_dtor(this);
432 if (flags & 1)
433 operator_delete(this);
435 return this;
438 /* ??_Gstreambuf@@UAEPAXI@Z */
439 DEFINE_THISCALL_WRAPPER(streambuf_scalar_dtor, 8)
440 streambuf* __thiscall streambuf_scalar_dtor(streambuf *this, unsigned int flags)
442 TRACE("(%p %x)\n", this, flags);
443 streambuf_dtor(this);
444 if (flags & 1) operator_delete(this);
445 return this;
448 /* ?doallocate@streambuf@@MAEHXZ */
449 /* ?doallocate@streambuf@@MEAAHXZ */
450 DEFINE_THISCALL_WRAPPER(streambuf_doallocate, 4)
451 #define call_streambuf_doallocate(this) CALL_VTBL_FUNC(this, 40, int, (streambuf*), (this))
452 int __thiscall streambuf_doallocate(streambuf *this)
454 char *reserve;
456 TRACE("(%p)\n", this);
457 reserve = operator_new(RESERVE_SIZE);
458 if (!reserve)
459 return EOF;
461 streambuf_setb(this, reserve, reserve + RESERVE_SIZE, 1);
462 return 1;
465 /* ?allocate@streambuf@@IAEHXZ */
466 /* ?allocate@streambuf@@IEAAHXZ */
467 DEFINE_THISCALL_WRAPPER(streambuf_allocate, 4)
468 int __thiscall streambuf_allocate(streambuf *this)
470 TRACE("(%p)\n", this);
471 if (this->base != NULL || this->unbuffered)
472 return 0;
473 return call_streambuf_doallocate(this);
476 /* ?base@streambuf@@IBEPADXZ */
477 /* ?base@streambuf@@IEBAPEADXZ */
478 DEFINE_THISCALL_WRAPPER(streambuf_base, 4)
479 char* __thiscall streambuf_base(const streambuf *this)
481 TRACE("(%p)\n", this);
482 return this->base;
485 /* ?blen@streambuf@@IBEHXZ */
486 /* ?blen@streambuf@@IEBAHXZ */
487 DEFINE_THISCALL_WRAPPER(streambuf_blen, 4)
488 int __thiscall streambuf_blen(const streambuf *this)
490 TRACE("(%p)\n", this);
491 return this->ebuf - this->base;
494 /* ?eback@streambuf@@IBEPADXZ */
495 /* ?eback@streambuf@@IEBAPEADXZ */
496 DEFINE_THISCALL_WRAPPER(streambuf_eback, 4)
497 char* __thiscall streambuf_eback(const streambuf *this)
499 TRACE("(%p)\n", this);
500 return this->eback;
503 /* ?ebuf@streambuf@@IBEPADXZ */
504 /* ?ebuf@streambuf@@IEBAPEADXZ */
505 DEFINE_THISCALL_WRAPPER(streambuf_ebuf, 4)
506 char* __thiscall streambuf_ebuf(const streambuf *this)
508 TRACE("(%p)\n", this);
509 return this->ebuf;
512 /* ?egptr@streambuf@@IBEPADXZ */
513 /* ?egptr@streambuf@@IEBAPEADXZ */
514 DEFINE_THISCALL_WRAPPER(streambuf_egptr, 4)
515 char* __thiscall streambuf_egptr(const streambuf *this)
517 TRACE("(%p)\n", this);
518 return this->egptr;
521 /* ?epptr@streambuf@@IBEPADXZ */
522 /* ?epptr@streambuf@@IEBAPEADXZ */
523 DEFINE_THISCALL_WRAPPER(streambuf_epptr, 4)
524 char* __thiscall streambuf_epptr(const streambuf *this)
526 TRACE("(%p)\n", this);
527 return this->epptr;
530 /* ?gptr@streambuf@@IBEPADXZ */
531 /* ?gptr@streambuf@@IEBAPEADXZ */
532 DEFINE_THISCALL_WRAPPER(streambuf_gptr, 4)
533 char* __thiscall streambuf_gptr(const streambuf *this)
535 TRACE("(%p)\n", this);
536 return this->gptr;
539 /* ?pbase@streambuf@@IBEPADXZ */
540 /* ?pbase@streambuf@@IEBAPEADXZ */
541 DEFINE_THISCALL_WRAPPER(streambuf_pbase, 4)
542 char* __thiscall streambuf_pbase(const streambuf *this)
544 TRACE("(%p)\n", this);
545 return this->pbase;
548 /* ?pptr@streambuf@@IBEPADXZ */
549 /* ?pptr@streambuf@@IEBAPEADXZ */
550 DEFINE_THISCALL_WRAPPER(streambuf_pptr, 4)
551 char* __thiscall streambuf_pptr(const streambuf *this)
553 TRACE("(%p)\n", this);
554 return this->pptr;
557 /* ?clrlock@streambuf@@QAEXXZ */
558 /* ?clrlock@streambuf@@QEAAXXZ */
559 DEFINE_THISCALL_WRAPPER(streambuf_clrlock, 4)
560 void __thiscall streambuf_clrlock(streambuf *this)
562 TRACE("(%p)\n", this);
563 if (this->do_lock <= 0)
564 this->do_lock++;
567 /* ?lock@streambuf@@QAEXXZ */
568 /* ?lock@streambuf@@QEAAXXZ */
569 DEFINE_THISCALL_WRAPPER(streambuf_lock, 4)
570 void __thiscall streambuf_lock(streambuf *this)
572 TRACE("(%p)\n", this);
573 if (this->do_lock < 0)
574 EnterCriticalSection(&this->lock);
577 /* ?lockptr@streambuf@@IAEPAU_CRT_CRITICAL_SECTION@@XZ */
578 /* ?lockptr@streambuf@@IEAAPEAU_CRT_CRITICAL_SECTION@@XZ */
579 DEFINE_THISCALL_WRAPPER(streambuf_lockptr, 4)
580 CRITICAL_SECTION* __thiscall streambuf_lockptr(streambuf *this)
582 TRACE("(%p)\n", this);
583 return &this->lock;
586 /* ?gbump@streambuf@@IAEXH@Z */
587 /* ?gbump@streambuf@@IEAAXH@Z */
588 DEFINE_THISCALL_WRAPPER(streambuf_gbump, 8)
589 void __thiscall streambuf_gbump(streambuf *this, int count)
591 TRACE("(%p %d)\n", this, count);
592 this->gptr += count;
595 /* ?pbump@streambuf@@IAEXH@Z */
596 /* ?pbump@streambuf@@IEAAXH@Z */
597 DEFINE_THISCALL_WRAPPER(streambuf_pbump, 8)
598 void __thiscall streambuf_pbump(streambuf *this, int count)
600 TRACE("(%p %d)\n", this, count);
601 this->pptr += count;
604 /* ?in_avail@streambuf@@QBEHXZ */
605 /* ?in_avail@streambuf@@QEBAHXZ */
606 DEFINE_THISCALL_WRAPPER(streambuf_in_avail, 4)
607 int __thiscall streambuf_in_avail(const streambuf *this)
609 TRACE("(%p)\n", this);
610 return (this->egptr - this->gptr > 0) ? this->egptr - this->gptr : 0;
613 /* ?out_waiting@streambuf@@QBEHXZ */
614 /* ?out_waiting@streambuf@@QEBAHXZ */
615 DEFINE_THISCALL_WRAPPER(streambuf_out_waiting, 4)
616 int __thiscall streambuf_out_waiting(const streambuf *this)
618 TRACE("(%p)\n", this);
619 return (this->pptr - this->pbase > 0) ? this->pptr - this->pbase : 0;
622 /* Unexported */
623 DEFINE_THISCALL_WRAPPER(streambuf_overflow, 8)
624 #define call_streambuf_overflow(this, c) CALL_VTBL_FUNC(this, 28, int, (streambuf*, int), (this, c))
625 int __thiscall streambuf_overflow(streambuf *this, int c)
627 ERR("overflow is not implemented in streambuf\n");
628 return EOF;
631 /* ?seekoff@streambuf@@UAEJJW4seek_dir@ios@@H@Z */
632 /* ?seekoff@streambuf@@UEAAJJW4seek_dir@ios@@H@Z */
633 DEFINE_THISCALL_WRAPPER(streambuf_seekoff, 16)
634 #define call_streambuf_seekoff(this, off, dir, mode) CALL_VTBL_FUNC(this, 12, streampos, (streambuf*, streamoff, ios_seek_dir, int), (this, off, dir, mode))
635 streampos __thiscall streambuf_seekoff(streambuf *this, streamoff offset, ios_seek_dir dir, int mode)
637 TRACE("(%p %ld %d %d)\n", this, offset, dir, mode);
638 return EOF;
641 /* ?seekpos@streambuf@@UAEJJH@Z */
642 /* ?seekpos@streambuf@@UEAAJJH@Z */
643 DEFINE_THISCALL_WRAPPER(streambuf_seekpos, 12)
644 streampos __thiscall streambuf_seekpos(streambuf *this, streampos pos, int mode)
646 TRACE("(%p %ld %d)\n", this, pos, mode);
647 return call_streambuf_seekoff(this, pos, SEEKDIR_beg, mode);
650 /* ?pbackfail@streambuf@@UAEHH@Z */
651 /* ?pbackfail@streambuf@@UEAAHH@Z */
652 DEFINE_THISCALL_WRAPPER(streambuf_pbackfail, 8)
653 #define call_streambuf_pbackfail(this, c) CALL_VTBL_FUNC(this, 36, int, (streambuf*, int), (this, c))
654 int __thiscall streambuf_pbackfail(streambuf *this, int c)
656 TRACE("(%p %d)\n", this, c);
657 if (this->gptr > this->eback)
658 return *--this->gptr = c;
659 if (call_streambuf_seekoff(this, -1, SEEKDIR_cur, OPENMODE_in) == EOF)
660 return EOF;
661 if (!this->unbuffered && this->egptr) {
662 /* 'c' should be the next character read */
663 memmove(this->gptr + 1, this->gptr, this->egptr - this->gptr - 1);
664 *this->gptr = c;
666 return c;
669 /* ?setb@streambuf@@IAEXPAD0H@Z */
670 /* ?setb@streambuf@@IEAAXPEAD0H@Z */
671 DEFINE_THISCALL_WRAPPER(streambuf_setb, 16)
672 void __thiscall streambuf_setb(streambuf *this, char *ba, char *eb, int delete)
674 TRACE("(%p %p %p %d)\n", this, ba, eb, delete);
675 if (this->allocated)
676 operator_delete(this->base);
677 this->allocated = delete;
678 this->base = ba;
679 this->ebuf = eb;
682 /* ?setbuf@streambuf@@UAEPAV1@PADH@Z */
683 /* ?setbuf@streambuf@@UEAAPEAV1@PEADH@Z */
684 DEFINE_THISCALL_WRAPPER(streambuf_setbuf, 12)
685 streambuf* __thiscall streambuf_setbuf(streambuf *this, char *buffer, int length)
687 TRACE("(%p %p %d)\n", this, buffer, length);
688 if (this->base != NULL)
689 return NULL;
691 if (buffer == NULL || !length) {
692 this->unbuffered = 1;
693 this->base = this->ebuf = NULL;
694 } else {
695 this->unbuffered = 0;
696 this->base = buffer;
697 this->ebuf = buffer + length;
699 return this;
702 /* ?setg@streambuf@@IAEXPAD00@Z */
703 /* ?setg@streambuf@@IEAAXPEAD00@Z */
704 DEFINE_THISCALL_WRAPPER(streambuf_setg, 16)
705 void __thiscall streambuf_setg(streambuf *this, char *ek, char *gp, char *eg)
707 TRACE("(%p %p %p %p)\n", this, ek, gp, eg);
708 this->eback = ek;
709 this->gptr = gp;
710 this->egptr = eg;
713 /* ?setlock@streambuf@@QAEXXZ */
714 /* ?setlock@streambuf@@QEAAXXZ */
715 DEFINE_THISCALL_WRAPPER(streambuf_setlock, 4)
716 void __thiscall streambuf_setlock(streambuf *this)
718 TRACE("(%p)\n", this);
719 this->do_lock--;
722 /* ?setp@streambuf@@IAEXPAD0@Z */
723 /* ?setp@streambuf@@IEAAXPEAD0@Z */
724 DEFINE_THISCALL_WRAPPER(streambuf_setp, 12)
725 void __thiscall streambuf_setp(streambuf *this, char *pb, char *ep)
727 TRACE("(%p %p %p)\n", this, pb, ep);
728 this->pbase = this->pptr = pb;
729 this->epptr = ep;
732 /* ?sync@streambuf@@UAEHXZ */
733 /* ?sync@streambuf@@UEAAHXZ */
734 DEFINE_THISCALL_WRAPPER(streambuf_sync, 4)
735 #define call_streambuf_sync(this) CALL_VTBL_FUNC(this, 4, int, (streambuf*), (this))
736 int __thiscall streambuf_sync(streambuf *this)
738 TRACE("(%p)\n", this);
739 return (this->gptr >= this->egptr && this->pbase >= this->pptr) ? 0 : EOF;
742 /* ?unbuffered@streambuf@@IAEXH@Z */
743 /* ?unbuffered@streambuf@@IEAAXH@Z */
744 DEFINE_THISCALL_WRAPPER(streambuf_unbuffered_set, 8)
745 void __thiscall streambuf_unbuffered_set(streambuf *this, int buf)
747 TRACE("(%p %d)\n", this, buf);
748 this->unbuffered = buf;
751 /* ?unbuffered@streambuf@@IBEHXZ */
752 /* ?unbuffered@streambuf@@IEBAHXZ */
753 DEFINE_THISCALL_WRAPPER(streambuf_unbuffered_get, 4)
754 int __thiscall streambuf_unbuffered_get(const streambuf *this)
756 TRACE("(%p)\n", this);
757 return this->unbuffered;
760 /* Unexported */
761 DEFINE_THISCALL_WRAPPER(streambuf_underflow, 4)
762 #define call_streambuf_underflow(this) CALL_VTBL_FUNC(this, 32, int, (streambuf*), (this))
763 int __thiscall streambuf_underflow(streambuf *this)
765 ERR("underflow is not implemented in streambuf\n");
766 return EOF;
769 /* ?unlock@streambuf@@QAEXXZ */
770 /* ?unlock@streambuf@@QEAAXXZ */
771 DEFINE_THISCALL_WRAPPER(streambuf_unlock, 4)
772 void __thiscall streambuf_unlock(streambuf *this)
774 TRACE("(%p)\n", this);
775 if (this->do_lock < 0)
776 LeaveCriticalSection(&this->lock);
779 /* ?xsgetn@streambuf@@UAEHPADH@Z */
780 /* ?xsgetn@streambuf@@UEAAHPEADH@Z */
781 DEFINE_THISCALL_WRAPPER(streambuf_xsgetn, 12)
782 #define call_streambuf_xsgetn(this, buffer, count) CALL_VTBL_FUNC(this, 24, int, (streambuf*, char*, int), (this, buffer, count))
783 int __thiscall streambuf_xsgetn(streambuf *this, char *buffer, int count)
785 int copied = 0, chunk;
787 TRACE("(%p %p %d)\n", this, buffer, count);
789 if (this->unbuffered) {
790 if (this->stored_char == EOF)
791 this->stored_char = call_streambuf_underflow(this);
792 while (copied < count && this->stored_char != EOF) {
793 buffer[copied++] = this->stored_char;
794 this->stored_char = call_streambuf_underflow(this);
796 } else {
797 while (copied < count) {
798 if (call_streambuf_underflow(this) == EOF)
799 break;
800 chunk = this->egptr - this->gptr;
801 if (chunk > count - copied)
802 chunk = count - copied;
803 memcpy(buffer+copied, this->gptr, chunk);
804 this->gptr += chunk;
805 copied += chunk;
808 return copied;
811 /* ?xsputn@streambuf@@UAEHPBDH@Z */
812 /* ?xsputn@streambuf@@UEAAHPEBDH@Z */
813 DEFINE_THISCALL_WRAPPER(streambuf_xsputn, 12)
814 #define call_streambuf_xsputn(this, data, length) CALL_VTBL_FUNC(this, 20, int, (streambuf*, const char*, int), (this, data, length))
815 int __thiscall streambuf_xsputn(streambuf *this, const char *data, int length)
817 int copied = 0, chunk;
819 TRACE("(%p %p %d)\n", this, data, length);
821 while (copied < length) {
822 if (this->unbuffered || this->pptr == this->epptr) {
823 if (call_streambuf_overflow(this, data[copied]) == EOF)
824 break;
825 copied++;
826 } else {
827 chunk = this->epptr - this->pptr;
828 if (chunk > length - copied)
829 chunk = length - copied;
830 memcpy(this->pptr, data+copied, chunk);
831 this->pptr += chunk;
832 copied += chunk;
835 return copied;
838 /* ?sgetc@streambuf@@QAEHXZ */
839 /* ?sgetc@streambuf@@QEAAHXZ */
840 DEFINE_THISCALL_WRAPPER(streambuf_sgetc, 4)
841 int __thiscall streambuf_sgetc(streambuf *this)
843 TRACE("(%p)\n", this);
844 if (this->unbuffered) {
845 if (this->stored_char == EOF)
846 this->stored_char = call_streambuf_underflow(this);
847 return this->stored_char;
848 } else
849 return call_streambuf_underflow(this);
852 /* ?sputc@streambuf@@QAEHH@Z */
853 /* ?sputc@streambuf@@QEAAHH@Z */
854 DEFINE_THISCALL_WRAPPER(streambuf_sputc, 8)
855 int __thiscall streambuf_sputc(streambuf *this, int ch)
857 TRACE("(%p %d)\n", this, ch);
858 return (this->pptr < this->epptr) ? (unsigned char)(*this->pptr++ = ch) : call_streambuf_overflow(this, ch);
861 /* ?sgetn@streambuf@@QAEHPADH@Z */
862 /* ?sgetn@streambuf@@QEAAHPEADH@Z */
863 DEFINE_THISCALL_WRAPPER(streambuf_sgetn, 12)
864 int __thiscall streambuf_sgetn(streambuf *this, char *buffer, int count)
866 return call_streambuf_xsgetn(this, buffer, count);
869 /* ?sputn@streambuf@@QAEHPBDH@Z */
870 /* ?sputn@streambuf@@QEAAHPEBDH@Z */
871 DEFINE_THISCALL_WRAPPER(streambuf_sputn, 12)
872 int __thiscall streambuf_sputn(streambuf *this, const char *data, int length)
874 return call_streambuf_xsputn(this, data, length);
877 /* ?snextc@streambuf@@QAEHXZ */
878 /* ?snextc@streambuf@@QEAAHXZ */
879 DEFINE_THISCALL_WRAPPER(streambuf_snextc, 4)
880 int __thiscall streambuf_snextc(streambuf *this)
882 TRACE("(%p)\n", this);
883 if (this->unbuffered) {
884 if (this->stored_char == EOF)
885 call_streambuf_underflow(this);
886 return this->stored_char = call_streambuf_underflow(this);
887 } else {
888 if (this->gptr >= this->egptr)
889 call_streambuf_underflow(this);
890 this->gptr++;
891 return (this->gptr < this->egptr) ? (unsigned char)(*this->gptr) : call_streambuf_underflow(this);
895 /* ?sbumpc@streambuf@@QAEHXZ */
896 /* ?sbumpc@streambuf@@QEAAHXZ */
897 DEFINE_THISCALL_WRAPPER(streambuf_sbumpc, 4)
898 int __thiscall streambuf_sbumpc(streambuf *this)
900 int ret;
902 TRACE("(%p)\n", this);
904 if (this->unbuffered) {
905 ret = this->stored_char;
906 this->stored_char = EOF;
907 if (ret == EOF)
908 ret = call_streambuf_underflow(this);
909 } else {
910 ret = (this->gptr < this->egptr) ? (unsigned char)(*this->gptr) : call_streambuf_underflow(this);
911 this->gptr++;
913 return ret;
916 /* ?stossc@streambuf@@QAEXXZ */
917 /* ?stossc@streambuf@@QEAAXXZ */
918 DEFINE_THISCALL_WRAPPER(streambuf_stossc, 4)
919 void __thiscall streambuf_stossc(streambuf *this)
921 TRACE("(%p)\n", this);
922 if (this->unbuffered) {
923 if (this->stored_char == EOF)
924 call_streambuf_underflow(this);
925 else
926 this->stored_char = EOF;
927 } else {
928 if (this->gptr >= this->egptr)
929 call_streambuf_underflow(this);
930 if (this->gptr < this->egptr)
931 this->gptr++;
935 /* ?sputbackc@streambuf@@QAEHD@Z */
936 /* ?sputbackc@streambuf@@QEAAHD@Z */
937 DEFINE_THISCALL_WRAPPER(streambuf_sputbackc, 8)
938 int __thiscall streambuf_sputbackc(streambuf *this, char ch)
940 TRACE("(%p %d)\n", this, ch);
941 return call_streambuf_pbackfail(this, ch);
944 /* ?dbp@streambuf@@QAEXXZ */
945 /* ?dbp@streambuf@@QEAAXXZ */
946 DEFINE_THISCALL_WRAPPER(streambuf_dbp, 4)
947 void __thiscall streambuf_dbp(streambuf *this)
949 printf("\nSTREAMBUF DEBUG INFO: this=%p, ", this);
950 if (this->unbuffered) {
951 printf("unbuffered\n");
952 } else {
953 printf("_fAlloc=%d\n", this->allocated);
954 printf(" base()=%p, ebuf()=%p, blen()=%d\n", this->base, this->ebuf, streambuf_blen(this));
955 printf("pbase()=%p, pptr()=%p, epptr()=%p\n", this->pbase, this->pptr, this->epptr);
956 printf("eback()=%p, gptr()=%p, egptr()=%p\n", this->eback, this->gptr, this->egptr);
960 /* ??0filebuf@@QAE@ABV0@@Z */
961 /* ??0filebuf@@QEAA@AEBV0@@Z */
962 DEFINE_THISCALL_WRAPPER(filebuf_copy_ctor, 8)
963 filebuf* __thiscall filebuf_copy_ctor(filebuf* this, const filebuf *copy)
965 TRACE("(%p %p)\n", this, copy);
966 *this = *copy;
967 this->base.vtable = &filebuf_vtable;
968 return this;
971 /* ??0filebuf@@QAE@HPADH@Z */
972 /* ??0filebuf@@QEAA@HPEADH@Z */
973 DEFINE_THISCALL_WRAPPER(filebuf_fd_reserve_ctor, 16)
974 filebuf* __thiscall filebuf_fd_reserve_ctor(filebuf* this, filedesc fd, char *buffer, int length)
976 TRACE("(%p %d %p %d)\n", this, fd, buffer, length);
977 streambuf_reserve_ctor(&this->base, buffer, length);
978 this->base.vtable = &filebuf_vtable;
979 this->fd = fd;
980 this->close = 0;
981 return this;
984 /* ??0filebuf@@QAE@H@Z */
985 /* ??0filebuf@@QEAA@H@Z */
986 DEFINE_THISCALL_WRAPPER(filebuf_fd_ctor, 8)
987 filebuf* __thiscall filebuf_fd_ctor(filebuf* this, filedesc fd)
989 filebuf_fd_reserve_ctor(this, fd, NULL, 0);
990 this->base.unbuffered = 0;
991 return this;
994 /* ??0filebuf@@QAE@XZ */
995 /* ??0filebuf@@QEAA@XZ */
996 DEFINE_THISCALL_WRAPPER(filebuf_ctor, 4)
997 filebuf* __thiscall filebuf_ctor(filebuf* this)
999 return filebuf_fd_ctor(this, -1);
1002 /* ??1filebuf@@UAE@XZ */
1003 /* ??1filebuf@@UEAA@XZ */
1004 DEFINE_THISCALL_WRAPPER(filebuf_dtor, 4)
1005 void __thiscall filebuf_dtor(filebuf* this)
1007 TRACE("(%p)\n", this);
1008 if (this->close)
1009 filebuf_close(this);
1010 streambuf_dtor(&this->base);
1013 /* ??4filebuf@@QAEAAV0@ABV0@@Z */
1014 /* ??4filebuf@@QEAAAEAV0@AEBV0@@Z */
1015 DEFINE_THISCALL_WRAPPER(filebuf_assign, 8)
1016 filebuf* __thiscall filebuf_assign(filebuf* this, const filebuf *rhs)
1018 filebuf_dtor(this);
1019 return filebuf_copy_ctor(this, rhs);
1022 /* ??_Efilebuf@@UAEPAXI@Z */
1023 DEFINE_THISCALL_WRAPPER(filebuf_vector_dtor, 8)
1024 filebuf* __thiscall filebuf_vector_dtor(filebuf *this, unsigned int flags)
1026 TRACE("(%p %x)\n", this, flags);
1027 if (flags & 2) {
1028 /* we have an array, with the number of elements stored before the first object */
1029 INT_PTR i, *ptr = (INT_PTR *)this-1;
1031 for (i = *ptr-1; i >= 0; i--)
1032 filebuf_dtor(this+i);
1033 operator_delete(ptr);
1034 } else {
1035 filebuf_dtor(this);
1036 if (flags & 1)
1037 operator_delete(this);
1039 return this;
1042 /* ??_Gfilebuf@@UAEPAXI@Z */
1043 DEFINE_THISCALL_WRAPPER(filebuf_scalar_dtor, 8)
1044 filebuf* __thiscall filebuf_scalar_dtor(filebuf *this, unsigned int flags)
1046 TRACE("(%p %x)\n", this, flags);
1047 filebuf_dtor(this);
1048 if (flags & 1) operator_delete(this);
1049 return this;
1052 /* ?attach@filebuf@@QAEPAV1@H@Z */
1053 /* ?attach@filebuf@@QEAAPEAV1@H@Z */
1054 DEFINE_THISCALL_WRAPPER(filebuf_attach, 8)
1055 filebuf* __thiscall filebuf_attach(filebuf *this, filedesc fd)
1057 TRACE("(%p %d)\n", this, fd);
1058 if (this->fd != -1)
1059 return NULL;
1061 streambuf_lock(&this->base);
1062 this->fd = fd;
1063 streambuf_allocate(&this->base);
1064 streambuf_unlock(&this->base);
1065 return this;
1068 /* ?close@filebuf@@QAEPAV1@XZ */
1069 /* ?close@filebuf@@QEAAPEAV1@XZ */
1070 DEFINE_THISCALL_WRAPPER(filebuf_close, 4)
1071 filebuf* __thiscall filebuf_close(filebuf *this)
1073 filebuf *ret;
1075 TRACE("(%p)\n", this);
1076 if (this->fd == -1)
1077 return NULL;
1079 streambuf_lock(&this->base);
1080 if (call_streambuf_sync(&this->base) == EOF || _close(this->fd) < 0) {
1081 ret = NULL;
1082 } else {
1083 this->fd = -1;
1084 ret = this;
1086 streambuf_unlock(&this->base);
1087 return ret;
1090 /* ?fd@filebuf@@QBEHXZ */
1091 /* ?fd@filebuf@@QEBAHXZ */
1092 DEFINE_THISCALL_WRAPPER(filebuf_fd, 4)
1093 filedesc __thiscall filebuf_fd(const filebuf *this)
1095 TRACE("(%p)\n", this);
1096 return this->fd;
1099 /* ?is_open@filebuf@@QBEHXZ */
1100 /* ?is_open@filebuf@@QEBAHXZ */
1101 DEFINE_THISCALL_WRAPPER(filebuf_is_open, 4)
1102 int __thiscall filebuf_is_open(const filebuf *this)
1104 TRACE("(%p)\n", this);
1105 return this->fd != -1;
1108 /* ?open@filebuf@@QAEPAV1@PBDHH@Z */
1109 /* ?open@filebuf@@QEAAPEAV1@PEBDHH@Z */
1110 DEFINE_THISCALL_WRAPPER(filebuf_open, 16)
1111 filebuf* __thiscall filebuf_open(filebuf *this, const char *name, ios_open_mode mode, int protection)
1113 const int inout_mode[4] = {-1, _O_RDONLY, _O_WRONLY, _O_RDWR};
1114 const int share_mode[4] = {_SH_DENYRW, _SH_DENYWR, _SH_DENYRD, _SH_DENYNO};
1115 int op_flags, sh_flags, fd;
1117 TRACE("(%p %s %x %x)\n", this, name, mode, protection);
1118 if (this->fd != -1)
1119 return NULL;
1121 /* mode */
1122 if (mode & (OPENMODE_app|OPENMODE_trunc))
1123 mode |= OPENMODE_out;
1124 op_flags = inout_mode[mode & (OPENMODE_in|OPENMODE_out)];
1125 if (op_flags < 0)
1126 return NULL;
1127 if (mode & OPENMODE_app)
1128 op_flags |= _O_APPEND;
1129 if ((mode & OPENMODE_trunc) ||
1130 ((mode & OPENMODE_out) && !(mode & (OPENMODE_in|OPENMODE_app|OPENMODE_ate))))
1131 op_flags |= _O_TRUNC;
1132 if (!(mode & OPENMODE_nocreate))
1133 op_flags |= _O_CREAT;
1134 if (mode & OPENMODE_noreplace)
1135 op_flags |= _O_EXCL;
1136 op_flags |= (mode & OPENMODE_binary) ? _O_BINARY : _O_TEXT;
1138 /* share protection */
1139 sh_flags = (protection & filebuf_sh_none) ? share_mode[(protection >> 9) & 3] : _SH_DENYNO;
1141 TRACE("op_flags %x, sh_flags %x\n", op_flags, sh_flags);
1142 fd = _sopen(name, op_flags, sh_flags, _S_IREAD|_S_IWRITE);
1143 if (fd < 0)
1144 return NULL;
1146 streambuf_lock(&this->base);
1147 this->close = 1;
1148 this->fd = fd;
1149 if ((mode & OPENMODE_ate) &&
1150 call_streambuf_seekoff(&this->base, 0, SEEKDIR_end, mode & (OPENMODE_in|OPENMODE_out)) == EOF) {
1151 _close(fd);
1152 this->fd = -1;
1154 streambuf_allocate(&this->base);
1155 streambuf_unlock(&this->base);
1156 return (this->fd == -1) ? NULL : this;
1159 /* ?overflow@filebuf@@UAEHH@Z */
1160 /* ?overflow@filebuf@@UEAAHH@Z */
1161 DEFINE_THISCALL_WRAPPER(filebuf_overflow, 8)
1162 int __thiscall filebuf_overflow(filebuf *this, int c)
1164 TRACE("(%p %d)\n", this, c);
1165 if (call_streambuf_sync(&this->base) == EOF)
1166 return EOF;
1167 if (this->base.unbuffered)
1168 return (c == EOF) ? 1 : _write(this->fd, &c, 1);
1169 if (streambuf_allocate(&this->base) == EOF)
1170 return EOF;
1172 this->base.pbase = this->base.pptr = this->base.base;
1173 this->base.epptr = this->base.ebuf;
1174 if (c != EOF)
1175 *this->base.pptr++ = c;
1176 return 1;
1179 /* ?seekoff@filebuf@@UAEJJW4seek_dir@ios@@H@Z */
1180 /* ?seekoff@filebuf@@UEAAJJW4seek_dir@ios@@H@Z */
1181 DEFINE_THISCALL_WRAPPER(filebuf_seekoff, 16)
1182 streampos __thiscall filebuf_seekoff(filebuf *this, streamoff offset, ios_seek_dir dir, int mode)
1184 TRACE("(%p %ld %d %d)\n", this, offset, dir, mode);
1185 if (call_streambuf_sync(&this->base) == EOF)
1186 return EOF;
1187 return _lseek(this->fd, offset, dir);
1190 /* ?setbuf@filebuf@@UAEPAVstreambuf@@PADH@Z */
1191 /* ?setbuf@filebuf@@UEAAPEAVstreambuf@@PEADH@Z */
1192 DEFINE_THISCALL_WRAPPER(filebuf_setbuf, 12)
1193 streambuf* __thiscall filebuf_setbuf(filebuf *this, char *buffer, int length)
1195 TRACE("(%p %p %d)\n", this, buffer, length);
1197 if (filebuf_is_open(this) && this->base.base != NULL)
1198 return NULL;
1200 streambuf_lock(&this->base);
1202 if (buffer == NULL || !length) {
1203 this->base.unbuffered = 1;
1204 } else {
1205 if (this->base.allocated) {
1206 operator_delete(this->base.base);
1207 this->base.allocated = 0;
1210 this->base.base = buffer;
1211 this->base.ebuf = buffer + length;
1214 streambuf_unlock(&this->base);
1216 return &this->base;
1219 /* ?setmode@filebuf@@QAEHH@Z */
1220 /* ?setmode@filebuf@@QEAAHH@Z */
1221 DEFINE_THISCALL_WRAPPER(filebuf_setmode, 8)
1222 int __thiscall filebuf_setmode(filebuf *this, int mode)
1224 int ret;
1226 TRACE("(%p %d)\n", this, mode);
1227 if (mode != filebuf_text && mode != filebuf_binary)
1228 return -1;
1230 streambuf_lock(&this->base);
1231 ret = (call_streambuf_sync(&this->base) == EOF) ? -1 : _setmode(this->fd, mode);
1232 streambuf_unlock(&this->base);
1233 return ret;
1236 /* ?sync@filebuf@@UAEHXZ */
1237 /* ?sync@filebuf@@UEAAHXZ */
1238 DEFINE_THISCALL_WRAPPER(filebuf_sync, 4)
1239 int __thiscall filebuf_sync(filebuf *this)
1241 int count, mode;
1242 char *ptr;
1243 LONG offset;
1245 TRACE("(%p)\n", this);
1246 if (this->fd == -1)
1247 return EOF;
1248 if (this->base.unbuffered)
1249 return 0;
1251 /* flush output buffer */
1252 if (this->base.pptr != NULL) {
1253 count = this->base.pptr - this->base.pbase;
1254 if (count > 0 && _write(this->fd, this->base.pbase, count) != count)
1255 return EOF;
1257 this->base.pbase = this->base.pptr = this->base.epptr = NULL;
1258 /* flush input buffer */
1259 if (this->base.egptr != NULL) {
1260 offset = this->base.egptr - this->base.gptr;
1261 if (offset > 0) {
1262 mode = _setmode(this->fd, _O_TEXT);
1263 _setmode(this->fd, mode);
1264 if (mode & _O_TEXT) {
1265 /* in text mode, '\n' in the buffer means '\r\n' in the file */
1266 for (ptr = this->base.gptr; ptr < this->base.egptr; ptr++)
1267 if (*ptr == '\n')
1268 offset++;
1270 if (_lseek(this->fd, -offset, SEEK_CUR) < 0)
1271 return EOF;
1274 this->base.eback = this->base.gptr = this->base.egptr = NULL;
1275 return 0;
1278 /* ?underflow@filebuf@@UAEHXZ */
1279 /* ?underflow@filebuf@@UEAAHXZ */
1280 DEFINE_THISCALL_WRAPPER(filebuf_underflow, 4)
1281 int __thiscall filebuf_underflow(filebuf *this)
1283 int buffer_size, read_bytes;
1284 char c;
1286 TRACE("(%p)\n", this);
1288 if (this->base.unbuffered)
1289 return (_read(this->fd, &c, 1) < 1) ? EOF : (unsigned char) c;
1291 if (this->base.gptr >= this->base.egptr) {
1292 if (call_streambuf_sync(&this->base) == EOF)
1293 return EOF;
1294 buffer_size = this->base.ebuf - this->base.base;
1295 read_bytes = _read(this->fd, this->base.base, buffer_size);
1296 if (read_bytes <= 0)
1297 return EOF;
1298 this->base.eback = this->base.gptr = this->base.base;
1299 this->base.egptr = this->base.base + read_bytes;
1301 return (unsigned char) *this->base.gptr;
1304 /* ??0strstreambuf@@QAE@ABV0@@Z */
1305 /* ??0strstreambuf@@QEAA@AEBV0@@Z */
1306 DEFINE_THISCALL_WRAPPER(strstreambuf_copy_ctor, 8)
1307 strstreambuf* __thiscall strstreambuf_copy_ctor(strstreambuf *this, const strstreambuf *copy)
1309 TRACE("(%p %p)\n", this, copy);
1310 *this = *copy;
1311 this->base.vtable = &strstreambuf_vtable;
1312 return this;
1315 /* ??0strstreambuf@@QAE@H@Z */
1316 /* ??0strstreambuf@@QEAA@H@Z */
1317 DEFINE_THISCALL_WRAPPER(strstreambuf_dynamic_ctor, 8)
1318 strstreambuf* __thiscall strstreambuf_dynamic_ctor(strstreambuf* this, int length)
1320 TRACE("(%p %d)\n", this, length);
1321 streambuf_ctor(&this->base);
1322 this->base.vtable = &strstreambuf_vtable;
1323 this->dynamic = 1;
1324 this->increase = length;
1325 this->constant = 0;
1326 this->f_alloc = NULL;
1327 this->f_free = NULL;
1328 return this;
1331 /* ??0strstreambuf@@QAE@P6APAXJ@ZP6AXPAX@Z@Z */
1332 /* ??0strstreambuf@@QEAA@P6APEAXJ@ZP6AXPEAX@Z@Z */
1333 DEFINE_THISCALL_WRAPPER(strstreambuf_funcs_ctor, 12)
1334 strstreambuf* __thiscall strstreambuf_funcs_ctor(strstreambuf* this, allocFunction falloc, freeFunction ffree)
1336 TRACE("(%p %p %p)\n", this, falloc, ffree);
1337 strstreambuf_dynamic_ctor(this, 1);
1338 this->f_alloc = falloc;
1339 this->f_free = ffree;
1340 return this;
1343 /* ??0strstreambuf@@QAE@PADH0@Z */
1344 /* ??0strstreambuf@@QEAA@PEADH0@Z */
1345 DEFINE_THISCALL_WRAPPER(strstreambuf_buffer_ctor, 16)
1346 strstreambuf* __thiscall strstreambuf_buffer_ctor(strstreambuf *this, char *buffer, int length, char *put)
1348 char *end_buffer;
1350 TRACE("(%p %p %d %p)\n", this, buffer, length, put);
1352 if (length > 0)
1353 end_buffer = buffer + length;
1354 else if (length == 0)
1355 end_buffer = buffer + strlen(buffer);
1356 else
1357 end_buffer = (char*) -1;
1359 streambuf_ctor(&this->base);
1360 streambuf_setb(&this->base, buffer, end_buffer, 0);
1361 if (put == NULL) {
1362 streambuf_setg(&this->base, buffer, buffer, end_buffer);
1363 } else {
1364 streambuf_setg(&this->base, buffer, buffer, put);
1365 streambuf_setp(&this->base, put, end_buffer);
1367 this->base.vtable = &strstreambuf_vtable;
1368 this->dynamic = 0;
1369 this->constant = 1;
1370 return this;
1373 /* ??0strstreambuf@@QAE@PAEH0@Z */
1374 /* ??0strstreambuf@@QEAA@PEAEH0@Z */
1375 DEFINE_THISCALL_WRAPPER(strstreambuf_ubuffer_ctor, 16)
1376 strstreambuf* __thiscall strstreambuf_ubuffer_ctor(strstreambuf *this, unsigned char *buffer, int length, unsigned char *put)
1378 TRACE("(%p %p %d %p)\n", this, buffer, length, put);
1379 return strstreambuf_buffer_ctor(this, (char*)buffer, length, (char*)put);
1382 /* ??0strstreambuf@@QAE@XZ */
1383 /* ??0strstreambuf@@QEAA@XZ */
1384 DEFINE_THISCALL_WRAPPER(strstreambuf_ctor, 4)
1385 strstreambuf* __thiscall strstreambuf_ctor(strstreambuf *this)
1387 TRACE("(%p)\n", this);
1388 return strstreambuf_dynamic_ctor(this, 1);
1391 /* ??1strstreambuf@@UAE@XZ */
1392 /* ??1strstreambuf@@UEAA@XZ */
1393 DEFINE_THISCALL_WRAPPER(strstreambuf_dtor, 4)
1394 void __thiscall strstreambuf_dtor(strstreambuf *this)
1396 TRACE("(%p)\n", this);
1397 if (this->dynamic && this->base.base) {
1398 if (this->f_free)
1399 this->f_free(this->base.base);
1400 else
1401 operator_delete(this->base.base);
1403 streambuf_dtor(&this->base);
1406 /* ??4strstreambuf@@QAEAAV0@ABV0@@Z */
1407 /* ??4strstreambuf@@QEAAAEAV0@AEBV0@@Z */
1408 DEFINE_THISCALL_WRAPPER(strstreambuf_assign, 8)
1409 strstreambuf* __thiscall strstreambuf_assign(strstreambuf *this, const strstreambuf *rhs)
1411 strstreambuf_dtor(this);
1412 return strstreambuf_copy_ctor(this, rhs);
1415 /* ??_Estrstreambuf@@UAEPAXI@Z */
1416 DEFINE_THISCALL_WRAPPER(strstreambuf_vector_dtor, 8)
1417 strstreambuf* __thiscall strstreambuf_vector_dtor(strstreambuf *this, unsigned int flags)
1419 TRACE("(%p %x)\n", this, flags);
1420 if (flags & 2) {
1421 /* we have an array, with the number of elements stored before the first object */
1422 INT_PTR i, *ptr = (INT_PTR *)this-1;
1424 for (i = *ptr-1; i >= 0; i--)
1425 strstreambuf_dtor(this+i);
1426 operator_delete(ptr);
1427 } else {
1428 strstreambuf_dtor(this);
1429 if (flags & 1)
1430 operator_delete(this);
1432 return this;
1435 /* ??_Gstrstreambuf@@UAEPAXI@Z */
1436 DEFINE_THISCALL_WRAPPER(strstreambuf_scalar_dtor, 8)
1437 strstreambuf* __thiscall strstreambuf_scalar_dtor(strstreambuf *this, unsigned int flags)
1439 TRACE("(%p %x)\n", this, flags);
1440 strstreambuf_dtor(this);
1441 if (flags & 1) operator_delete(this);
1442 return this;
1445 /* ?doallocate@strstreambuf@@MAEHXZ */
1446 /* ?doallocate@strstreambuf@@MEAAHXZ */
1447 DEFINE_THISCALL_WRAPPER(strstreambuf_doallocate, 4)
1448 int __thiscall strstreambuf_doallocate(strstreambuf *this)
1450 char *prev_buffer = this->base.base, *new_buffer;
1451 LONG prev_size = this->base.ebuf - this->base.base, new_size;
1453 TRACE("(%p)\n", this);
1455 /* calculate the size of the new buffer */
1456 new_size = (prev_size > 0 ? prev_size : 0) + (this->increase > 0 ? this->increase : 1);
1457 /* get a new buffer */
1458 if (this->f_alloc)
1459 new_buffer = this->f_alloc(new_size);
1460 else
1461 new_buffer = operator_new(new_size);
1462 if (!new_buffer)
1463 return EOF;
1464 if (this->base.ebuf) {
1465 /* copy the contents and adjust the pointers */
1466 memcpy(new_buffer, this->base.base, prev_size);
1467 if (this->base.egptr) {
1468 this->base.eback += new_buffer - prev_buffer;
1469 this->base.gptr += new_buffer - prev_buffer;
1470 this->base.egptr += new_buffer - prev_buffer;
1472 if (this->base.epptr) {
1473 this->base.pbase += new_buffer - prev_buffer;
1474 this->base.pptr += new_buffer - prev_buffer;
1475 this->base.epptr += new_buffer - prev_buffer;
1477 /* free the old buffer */
1478 if (this->f_free)
1479 this->f_free(this->base.base);
1480 else
1481 operator_delete(this->base.base);
1483 streambuf_setb(&this->base, new_buffer, new_buffer + new_size, 0);
1484 return 1;
1487 /* ?freeze@strstreambuf@@QAEXH@Z */
1488 /* ?freeze@strstreambuf@@QEAAXH@Z */
1489 DEFINE_THISCALL_WRAPPER(strstreambuf_freeze, 8)
1490 void __thiscall strstreambuf_freeze(strstreambuf *this, int frozen)
1492 TRACE("(%p %d)\n", this, frozen);
1493 if (!this->constant)
1494 this->dynamic = !frozen;
1497 /* ?overflow@strstreambuf@@UAEHH@Z */
1498 /* ?overflow@strstreambuf@@UEAAHH@Z */
1499 DEFINE_THISCALL_WRAPPER(strstreambuf_overflow, 8)
1500 int __thiscall strstreambuf_overflow(strstreambuf *this, int c)
1502 TRACE("(%p %d)\n", this, c);
1503 if (this->base.pptr >= this->base.epptr) {
1504 /* increase the buffer size if it's dynamic */
1505 if (!this->dynamic || call_streambuf_doallocate(&this->base) == EOF)
1506 return EOF;
1507 if (!this->base.epptr)
1508 this->base.pbase = this->base.pptr = this->base.egptr ? this->base.egptr : this->base.base;
1509 this->base.epptr = this->base.ebuf;
1511 if (c != EOF)
1512 *this->base.pptr++ = c;
1513 return 1;
1516 /* ?seekoff@strstreambuf@@UAEJJW4seek_dir@ios@@H@Z */
1517 /* ?seekoff@strstreambuf@@UEAAJJW4seek_dir@ios@@H@Z */
1518 DEFINE_THISCALL_WRAPPER(strstreambuf_seekoff, 16)
1519 streampos __thiscall strstreambuf_seekoff(strstreambuf *this, streamoff offset, ios_seek_dir dir, int mode)
1521 char *base[3];
1523 TRACE("(%p %ld %d %d)\n", this, offset, dir, mode);
1525 if ((unsigned int)dir > SEEKDIR_end || !(mode & (OPENMODE_in|OPENMODE_out)))
1526 return EOF;
1527 /* read buffer */
1528 if (mode & OPENMODE_in) {
1529 call_streambuf_underflow(&this->base);
1530 base[SEEKDIR_beg] = this->base.eback;
1531 base[SEEKDIR_cur] = this->base.gptr;
1532 base[SEEKDIR_end] = this->base.egptr;
1533 if (base[dir] + offset < this->base.eback || base[dir] + offset > this->base.egptr)
1534 return EOF;
1535 this->base.gptr = base[dir] + offset;
1537 /* write buffer */
1538 if (mode & OPENMODE_out) {
1539 if (!this->base.epptr && call_streambuf_overflow(&this->base, EOF) == EOF)
1540 return EOF;
1541 base[SEEKDIR_beg] = this->base.pbase;
1542 base[SEEKDIR_cur] = this->base.pptr;
1543 base[SEEKDIR_end] = this->base.epptr;
1544 if (base[dir] + offset < this->base.pbase)
1545 return EOF;
1546 if (base[dir] + offset > this->base.epptr) {
1547 /* make room if the buffer is dynamic */
1548 if (!this->dynamic)
1549 return EOF;
1550 this->increase = offset;
1551 if (call_streambuf_doallocate(&this->base) == EOF)
1552 return EOF;
1554 this->base.pptr = base[dir] + offset;
1555 return this->base.pptr - base[SEEKDIR_beg];
1557 return this->base.gptr - base[SEEKDIR_beg];
1560 /* ?setbuf@strstreambuf@@UAEPAVstreambuf@@PADH@Z */
1561 /* ?setbuf@strstreambuf@@UEAAPEAVstreambuf@@PEADH@Z */
1562 DEFINE_THISCALL_WRAPPER(strstreambuf_setbuf, 12)
1563 streambuf* __thiscall strstreambuf_setbuf(strstreambuf *this, char *buffer, int length)
1565 TRACE("(%p %p %d)\n", this, buffer, length);
1566 if (length)
1567 this->increase = length;
1568 return &this->base;
1571 /* ?str@strstreambuf@@QAEPADXZ */
1572 /* ?str@strstreambuf@@QEAAPEADXZ */
1573 DEFINE_THISCALL_WRAPPER(strstreambuf_str, 4)
1574 char* __thiscall strstreambuf_str(strstreambuf *this)
1576 TRACE("(%p)\n", this);
1577 strstreambuf_freeze(this, 1);
1578 return this->base.base;
1581 /* ?sync@strstreambuf@@UAEHXZ */
1582 /* ?sync@strstreambuf@@UEAAHXZ */
1583 DEFINE_THISCALL_WRAPPER(strstreambuf_sync, 4)
1584 int __thiscall strstreambuf_sync(strstreambuf *this)
1586 TRACE("(%p)\n", this);
1587 return 0;
1590 /* ?underflow@strstreambuf@@UAEHXZ */
1591 /* ?underflow@strstreambuf@@UEAAHXZ */
1592 DEFINE_THISCALL_WRAPPER(strstreambuf_underflow, 4)
1593 int __thiscall strstreambuf_underflow(strstreambuf *this)
1595 TRACE("(%p)\n", this);
1596 if (this->base.gptr < this->base.egptr)
1597 return (unsigned char) *this->base.gptr;
1598 /* extend the get area to include the characters written */
1599 if (this->base.egptr < this->base.pptr) {
1600 this->base.gptr = this->base.base + (this->base.gptr - this->base.eback);
1601 this->base.eback = this->base.base;
1602 this->base.egptr = this->base.pptr;
1604 return (this->base.gptr < this->base.egptr) ? (unsigned char)(*this->base.gptr) : EOF;
1607 /* ??0stdiobuf@@QAE@ABV0@@Z */
1608 /* ??0stdiobuf@@QEAA@AEBV0@@Z */
1609 DEFINE_THISCALL_WRAPPER(stdiobuf_copy_ctor, 8)
1610 stdiobuf* __thiscall stdiobuf_copy_ctor(stdiobuf *this, const stdiobuf *copy)
1612 TRACE("(%p %p)\n", this, copy);
1613 *this = *copy;
1614 this->base.vtable = &stdiobuf_vtable;
1615 return this;
1618 /* ??0stdiobuf@@QAE@PAU_iobuf@@@Z */
1619 /* ??0stdiobuf@@QEAA@PEAU_iobuf@@@Z */
1620 DEFINE_THISCALL_WRAPPER(stdiobuf_file_ctor, 8)
1621 stdiobuf* __thiscall stdiobuf_file_ctor(stdiobuf *this, FILE *file)
1623 TRACE("(%p %p)\n", this, file);
1624 streambuf_reserve_ctor(&this->base, NULL, 0);
1625 this->base.vtable = &stdiobuf_vtable;
1626 this->file = file;
1627 return this;
1630 /* ??1stdiobuf@@UAE@XZ */
1631 /* ??1stdiobuf@@UEAA@XZ */
1632 DEFINE_THISCALL_WRAPPER(stdiobuf_dtor, 4)
1633 void __thiscall stdiobuf_dtor(stdiobuf *this)
1635 TRACE("(%p)\n", this);
1636 call_streambuf_sync(&this->base);
1637 streambuf_dtor(&this->base);
1640 /* ??4stdiobuf@@QAEAAV0@ABV0@@Z */
1641 /* ??4stdiobuf@@QEAAAEAV0@AEBV0@@Z */
1642 DEFINE_THISCALL_WRAPPER(stdiobuf_assign, 8)
1643 stdiobuf* __thiscall stdiobuf_assign(stdiobuf *this, const stdiobuf *rhs)
1645 stdiobuf_dtor(this);
1646 return stdiobuf_copy_ctor(this, rhs);
1649 /* ??_Estdiobuf@@UAEPAXI@Z */
1650 DEFINE_THISCALL_WRAPPER(stdiobuf_vector_dtor, 8)
1651 stdiobuf* __thiscall stdiobuf_vector_dtor(stdiobuf *this, unsigned int flags)
1653 TRACE("(%p %x)\n", this, flags);
1654 if (flags & 2) {
1655 /* we have an array, with the number of elements stored before the first object */
1656 INT_PTR i, *ptr = (INT_PTR *)this-1;
1658 for (i = *ptr-1; i >= 0; i--)
1659 stdiobuf_dtor(this+i);
1660 operator_delete(ptr);
1661 } else {
1662 stdiobuf_dtor(this);
1663 if (flags & 1)
1664 operator_delete(this);
1666 return this;
1669 /* ??_Gstdiobuf@@UAEPAXI@Z */
1670 DEFINE_THISCALL_WRAPPER(stdiobuf_scalar_dtor, 8)
1671 stdiobuf* __thiscall stdiobuf_scalar_dtor(stdiobuf *this, unsigned int flags)
1673 TRACE("(%p %x)\n", this, flags);
1674 stdiobuf_dtor(this);
1675 if (flags & 1) operator_delete(this);
1676 return this;
1679 /* ?overflow@stdiobuf@@UAEHH@Z */
1680 /* ?overflow@stdiobuf@@UEAAHH@Z */
1681 DEFINE_THISCALL_WRAPPER(stdiobuf_overflow, 8)
1682 int __thiscall stdiobuf_overflow(stdiobuf *this, int c)
1684 TRACE("(%p %d)\n", this, c);
1685 if (this->base.unbuffered)
1686 return (c == EOF) ? 1 : fputc(c, this->file);
1687 if (streambuf_allocate(&this->base) == EOF)
1688 return EOF;
1690 if (!this->base.epptr) {
1691 /* set the put area to the second half of the buffer */
1692 streambuf_setp(&this->base,
1693 this->base.base + (this->base.ebuf - this->base.base) / 2, this->base.ebuf);
1694 } else if (this->base.pptr > this->base.pbase) {
1695 /* flush the put area */
1696 int count = this->base.pptr - this->base.pbase;
1697 if (fwrite(this->base.pbase, sizeof(char), count, this->file) != count)
1698 return EOF;
1699 this->base.pptr = this->base.pbase;
1701 if (c != EOF) {
1702 if (this->base.pbase >= this->base.epptr)
1703 return fputc(c, this->file);
1704 *this->base.pptr++ = c;
1706 return 1;
1709 /* ?pbackfail@stdiobuf@@UAEHH@Z */
1710 /* ?pbackfail@stdiobuf@@UEAAHH@Z */
1711 DEFINE_THISCALL_WRAPPER(stdiobuf_pbackfail, 8)
1712 int __thiscall stdiobuf_pbackfail(stdiobuf *this, int c)
1714 TRACE("(%p %d)\n", this, c);
1715 return streambuf_pbackfail(&this->base, c);
1718 /* ?seekoff@stdiobuf@@UAEJJW4seek_dir@ios@@H@Z */
1719 /* ?seekoff@stdiobuf@@UEAAJJW4seek_dir@ios@@H@Z */
1720 DEFINE_THISCALL_WRAPPER(stdiobuf_seekoff, 16)
1721 streampos __thiscall stdiobuf_seekoff(stdiobuf *this, streamoff offset, ios_seek_dir dir, int mode)
1723 TRACE("(%p %ld %d %d)\n", this, offset, dir, mode);
1724 call_streambuf_overflow(&this->base, EOF);
1725 if (fseek(this->file, offset, dir))
1726 return EOF;
1727 return ftell(this->file);
1730 /* ?setrwbuf@stdiobuf@@QAEHHH@Z */
1731 /* ?setrwbuf@stdiobuf@@QEAAHHH@Z */
1732 DEFINE_THISCALL_WRAPPER(stdiobuf_setrwbuf, 12)
1733 int __thiscall stdiobuf_setrwbuf(stdiobuf *this, int read_size, int write_size)
1735 char *reserve;
1736 int buffer_size = read_size + write_size;
1738 TRACE("(%p %d %d)\n", this, read_size, write_size);
1739 if (read_size < 0 || write_size < 0)
1740 return 0;
1741 if (!buffer_size) {
1742 this->base.unbuffered = 1;
1743 return 0;
1745 /* get a new buffer */
1746 reserve = operator_new(buffer_size);
1747 if (!reserve)
1748 return 0;
1749 streambuf_setb(&this->base, reserve, reserve + buffer_size, 1);
1750 this->base.unbuffered = 0;
1751 /* set the get/put areas */
1752 if (read_size > 0)
1753 streambuf_setg(&this->base, reserve, reserve + read_size, reserve + read_size);
1754 else
1755 streambuf_setg(&this->base, NULL, NULL, NULL);
1756 if (write_size > 0)
1757 streambuf_setp(&this->base, reserve + read_size, reserve + buffer_size);
1758 else
1759 streambuf_setp(&this->base, NULL, NULL);
1760 return 1;
1763 /* ?stdiofile@stdiobuf@@QAEPAU_iobuf@@XZ */
1764 /* ?stdiofile@stdiobuf@@QEAAPEAU_iobuf@@XZ */
1765 DEFINE_THISCALL_WRAPPER(stdiobuf_stdiofile, 4)
1766 FILE* __thiscall stdiobuf_stdiofile(stdiobuf *this)
1768 TRACE("(%p)\n", this);
1769 return this->file;
1772 /* ?sync@stdiobuf@@UAEHXZ */
1773 /* ?sync@stdiobuf@@UEAAHXZ */
1774 DEFINE_THISCALL_WRAPPER(stdiobuf_sync, 4)
1775 int __thiscall stdiobuf_sync(stdiobuf *this)
1777 TRACE("(%p)\n", this);
1778 if (this->base.unbuffered)
1779 return 0;
1780 /* flush the put area */
1781 if (call_streambuf_overflow(&this->base, EOF) == EOF)
1782 return EOF;
1783 /* flush the get area */
1784 if (this->base.gptr < this->base.egptr) {
1785 char *ptr;
1786 int fd, mode, offset = this->base.egptr - this->base.gptr;
1787 if ((fd = fileno(this->file)) < 0)
1788 return EOF;
1789 mode = _setmode(fd, _O_TEXT);
1790 _setmode(fd, mode);
1791 if (mode & _O_TEXT) {
1792 /* in text mode, '\n' in the buffer means '\r\n' in the file */
1793 for (ptr = this->base.gptr; ptr < this->base.egptr; ptr++)
1794 if (*ptr == '\n')
1795 offset++;
1797 if (fseek(this->file, -offset, SEEK_CUR))
1798 return EOF;
1799 this->base.gptr = this->base.egptr;
1801 return 0;
1804 /* ?underflow@stdiobuf@@UAEHXZ */
1805 /* ?underflow@stdiobuf@@UEAAHXZ */
1806 DEFINE_THISCALL_WRAPPER(stdiobuf_underflow, 4)
1807 int __thiscall stdiobuf_underflow(stdiobuf *this)
1809 TRACE("(%p)\n", this);
1810 if (!this->file)
1811 return EOF;
1812 if (this->base.unbuffered)
1813 return fgetc(this->file);
1814 if (streambuf_allocate(&this->base) == EOF)
1815 return EOF;
1817 if (!this->base.egptr) {
1818 /* set the get area to the first half of the buffer */
1819 char *middle = this->base.base + (this->base.ebuf - this->base.base) / 2;
1820 streambuf_setg(&this->base, this->base.base, middle, middle);
1822 if (this->base.gptr >= this->base.egptr) {
1823 /* read characters from the file */
1824 int buffer_size = this->base.egptr - this->base.eback, read_bytes;
1825 if (!this->base.eback ||
1826 (read_bytes = fread(this->base.eback, sizeof(char), buffer_size, this->file)) <= 0)
1827 return EOF;
1828 memmove(this->base.egptr - read_bytes, this->base.eback, read_bytes);
1829 this->base.gptr = this->base.egptr - read_bytes;
1831 return (unsigned char) *this->base.gptr++;
1834 /* ??0ios@@IAE@ABV0@@Z */
1835 /* ??0ios@@IEAA@AEBV0@@Z */
1836 DEFINE_THISCALL_WRAPPER(ios_copy_ctor, 8)
1837 ios* __thiscall ios_copy_ctor(ios *this, const ios *copy)
1839 TRACE("(%p %p)\n", this, copy);
1840 ios_fLockcInit++;
1841 this->vtable = &ios_vtable;
1842 this->sb = NULL;
1843 this->delbuf = 0;
1844 this->do_lock = -1;
1845 InitializeCriticalSection(&this->lock);
1846 return ios_assign(this, copy);
1849 /* ??0ios@@QAE@PAVstreambuf@@@Z */
1850 /* ??0ios@@QEAA@PEAVstreambuf@@@Z */
1851 DEFINE_THISCALL_WRAPPER(ios_sb_ctor, 8)
1852 ios* __thiscall ios_sb_ctor(ios *this, streambuf *sb)
1854 TRACE("(%p %p)\n", this, sb);
1855 ios_fLockcInit++;
1856 this->vtable = &ios_vtable;
1857 this->sb = sb;
1858 this->state = sb ? IOSTATE_goodbit : IOSTATE_badbit;
1859 this->special[0] = this->special[1] = 0;
1860 this->delbuf = 0;
1861 this->tie = NULL;
1862 this->flags = 0;
1863 this->precision = 6;
1864 this->fill = ' ';
1865 this->width = 0;
1866 this->do_lock = -1;
1867 InitializeCriticalSection(&this->lock);
1868 return this;
1871 /* ??0ios@@IAE@XZ */
1872 /* ??0ios@@IEAA@XZ */
1873 DEFINE_THISCALL_WRAPPER(ios_ctor, 4)
1874 ios* __thiscall ios_ctor(ios *this)
1876 return ios_sb_ctor(this, NULL);
1879 /* ??1ios@@UAE@XZ */
1880 /* ??1ios@@UEAA@XZ */
1881 DEFINE_THISCALL_WRAPPER(ios_dtor, 4)
1882 void __thiscall ios_dtor(ios *this)
1884 TRACE("(%p)\n", this);
1885 ios_fLockcInit--;
1886 if (this->delbuf && this->sb)
1887 call_streambuf_vector_dtor(this->sb, 1);
1888 this->sb = NULL;
1889 this->state = IOSTATE_badbit;
1890 DeleteCriticalSection(&this->lock);
1893 /* ??4ios@@IAEAAV0@ABV0@@Z */
1894 /* ??4ios@@IEAAAEAV0@AEBV0@@Z */
1895 DEFINE_THISCALL_WRAPPER(ios_assign, 8)
1896 ios* __thiscall ios_assign(ios *this, const ios *rhs)
1898 TRACE("(%p %p)\n", this, rhs);
1899 this->state = rhs->state;
1900 if (!this->sb)
1901 this->state |= IOSTATE_badbit;
1902 this->tie = rhs->tie;
1903 this->flags = rhs->flags;
1904 this->precision = (char) rhs->precision;
1905 this->fill = rhs->fill;
1906 this->width = (char) rhs->width;
1907 return this;
1910 /* ??7ios@@QBEHXZ */
1911 /* ??7ios@@QEBAHXZ */
1912 DEFINE_THISCALL_WRAPPER(ios_op_not, 4)
1913 int __thiscall ios_op_not(const ios *this)
1915 TRACE("(%p)\n", this);
1916 return ios_fail(this);
1919 /* ??Bios@@QBEPAXXZ */
1920 /* ??Bios@@QEBAPEAXXZ */
1921 DEFINE_THISCALL_WRAPPER(ios_op_void, 4)
1922 void* __thiscall ios_op_void(const ios *this)
1924 TRACE("(%p)\n", this);
1925 return ios_fail(this) ? NULL : (void*)this;
1928 /* ??_Eios@@UAEPAXI@Z */
1929 DEFINE_THISCALL_WRAPPER(ios_vector_dtor, 8)
1930 ios* __thiscall ios_vector_dtor(ios *this, unsigned int flags)
1932 TRACE("(%p %x)\n", this, flags);
1933 if (flags & 2) {
1934 /* we have an array, with the number of elements stored before the first object */
1935 INT_PTR i, *ptr = (INT_PTR *)this-1;
1937 for (i = *ptr-1; i >= 0; i--)
1938 ios_dtor(this+i);
1939 operator_delete(ptr);
1940 } else {
1941 ios_dtor(this);
1942 if (flags & 1)
1943 operator_delete(this);
1945 return this;
1948 /* ??_Gios@@UAEPAXI@Z */
1949 DEFINE_THISCALL_WRAPPER(ios_scalar_dtor, 8)
1950 ios* __thiscall ios_scalar_dtor(ios *this, unsigned int flags)
1952 TRACE("(%p %x)\n", this, flags);
1953 ios_dtor(this);
1954 if (flags & 1) operator_delete(this);
1955 return this;
1958 /* ?bad@ios@@QBEHXZ */
1959 /* ?bad@ios@@QEBAHXZ */
1960 DEFINE_THISCALL_WRAPPER(ios_bad, 4)
1961 int __thiscall ios_bad(const ios *this)
1963 TRACE("(%p)\n", this);
1964 return (this->state & IOSTATE_badbit);
1967 /* ?bitalloc@ios@@SAJXZ */
1968 LONG __cdecl ios_bitalloc(void)
1970 TRACE("()\n");
1971 ios_lockc();
1972 ios_maxbit <<= 1;
1973 ios_unlockc();
1974 return ios_maxbit;
1977 /* ?clear@ios@@QAEXH@Z */
1978 /* ?clear@ios@@QEAAXH@Z */
1979 DEFINE_THISCALL_WRAPPER(ios_clear, 8)
1980 void __thiscall ios_clear(ios *this, int state)
1982 TRACE("(%p %d)\n", this, state);
1983 ios_lock(this);
1984 this->state = state;
1985 ios_unlock(this);
1988 /* ?clrlock@ios@@QAAXXZ */
1989 /* ?clrlock@ios@@QEAAXXZ */
1990 void __cdecl ios_clrlock(ios *this)
1992 TRACE("(%p)\n", this);
1993 if (this->do_lock <= 0)
1994 this->do_lock++;
1995 if (this->sb)
1996 streambuf_clrlock(this->sb);
1999 /* ?delbuf@ios@@QAEXH@Z */
2000 /* ?delbuf@ios@@QEAAXH@Z */
2001 DEFINE_THISCALL_WRAPPER(ios_delbuf_set, 8)
2002 void __thiscall ios_delbuf_set(ios *this, int delete)
2004 TRACE("(%p %d)\n", this, delete);
2005 this->delbuf = delete;
2008 /* ?delbuf@ios@@QBEHXZ */
2009 /* ?delbuf@ios@@QEBAHXZ */
2010 DEFINE_THISCALL_WRAPPER(ios_delbuf_get, 4)
2011 int __thiscall ios_delbuf_get(const ios *this)
2013 TRACE("(%p)\n", this);
2014 return this->delbuf;
2017 /* ?dec@@YAAAVios@@AAV1@@Z */
2018 /* ?dec@@YAAEAVios@@AEAV1@@Z */
2019 ios* __cdecl ios_dec(ios *this)
2021 TRACE("(%p)\n", this);
2022 ios_setf_mask(this, FLAGS_dec, ios_basefield);
2023 return this;
2026 /* ?eof@ios@@QBEHXZ */
2027 /* ?eof@ios@@QEBAHXZ */
2028 DEFINE_THISCALL_WRAPPER(ios_eof, 4)
2029 int __thiscall ios_eof(const ios *this)
2031 TRACE("(%p)\n", this);
2032 return (this->state & IOSTATE_eofbit);
2035 /* ?fail@ios@@QBEHXZ */
2036 /* ?fail@ios@@QEBAHXZ */
2037 DEFINE_THISCALL_WRAPPER(ios_fail, 4)
2038 int __thiscall ios_fail(const ios *this)
2040 TRACE("(%p)\n", this);
2041 return (this->state & (IOSTATE_failbit|IOSTATE_badbit));
2044 /* ?fill@ios@@QAEDD@Z */
2045 /* ?fill@ios@@QEAADD@Z */
2046 DEFINE_THISCALL_WRAPPER(ios_fill_set, 8)
2047 char __thiscall ios_fill_set(ios *this, char fill)
2049 char prev = this->fill;
2051 TRACE("(%p %d)\n", this, fill);
2053 this->fill = fill;
2054 return prev;
2057 /* ?fill@ios@@QBEDXZ */
2058 /* ?fill@ios@@QEBADXZ */
2059 DEFINE_THISCALL_WRAPPER(ios_fill_get, 4)
2060 char __thiscall ios_fill_get(const ios *this)
2062 TRACE("(%p)\n", this);
2063 return this->fill;
2066 /* ?flags@ios@@QAEJJ@Z */
2067 /* ?flags@ios@@QEAAJJ@Z */
2068 DEFINE_THISCALL_WRAPPER(ios_flags_set, 8)
2069 LONG __thiscall ios_flags_set(ios *this, LONG flags)
2071 LONG prev = this->flags;
2073 TRACE("(%p %lx)\n", this, flags);
2075 this->flags = flags;
2076 return prev;
2079 /* ?flags@ios@@QBEJXZ */
2080 /* ?flags@ios@@QEBAJXZ */
2081 DEFINE_THISCALL_WRAPPER(ios_flags_get, 4)
2082 LONG __thiscall ios_flags_get(const ios *this)
2084 TRACE("(%p)\n", this);
2085 return this->flags;
2088 /* ?good@ios@@QBEHXZ */
2089 /* ?good@ios@@QEBAHXZ */
2090 DEFINE_THISCALL_WRAPPER(ios_good, 4)
2091 int __thiscall ios_good(const ios *this)
2093 TRACE("(%p)\n", this);
2094 return this->state == IOSTATE_goodbit;
2097 /* ?hex@@YAAAVios@@AAV1@@Z */
2098 /* ?hex@@YAAEAVios@@AEAV1@@Z */
2099 ios* __cdecl ios_hex(ios *this)
2101 TRACE("(%p)\n", this);
2102 ios_setf_mask(this, FLAGS_hex, ios_basefield);
2103 return this;
2106 /* ?init@ios@@IAEXPAVstreambuf@@@Z */
2107 /* ?init@ios@@IEAAXPEAVstreambuf@@@Z */
2108 DEFINE_THISCALL_WRAPPER(ios_init, 8)
2109 void __thiscall ios_init(ios *this, streambuf *sb)
2111 TRACE("(%p %p)\n", this, sb);
2112 if (this->delbuf && this->sb)
2113 call_streambuf_vector_dtor(this->sb, 1);
2114 this->sb = sb;
2115 if (sb == NULL)
2116 this->state |= IOSTATE_badbit;
2117 else
2118 this->state &= ~IOSTATE_badbit;
2121 /* ?iword@ios@@QBEAAJH@Z */
2122 /* ?iword@ios@@QEBAAEAJH@Z */
2123 DEFINE_THISCALL_WRAPPER(ios_iword, 8)
2124 LONG* __thiscall ios_iword(const ios *this, int index)
2126 TRACE("(%p %d)\n", this, index);
2127 return &ios_statebuf[index];
2130 /* ?lock@ios@@QAAXXZ */
2131 /* ?lock@ios@@QEAAXXZ */
2132 void __cdecl ios_lock(ios *this)
2134 TRACE("(%p)\n", this);
2135 if (this->do_lock < 0)
2136 EnterCriticalSection(&this->lock);
2139 /* ?lockbuf@ios@@QAAXXZ */
2140 /* ?lockbuf@ios@@QEAAXXZ */
2141 void __cdecl ios_lockbuf(ios *this)
2143 TRACE("(%p)\n", this);
2144 streambuf_lock(this->sb);
2147 /* ?lockc@ios@@KAXXZ */
2148 void __cdecl ios_lockc(void)
2150 TRACE("()\n");
2151 EnterCriticalSection(&ios_static_lock);
2154 /* ?lockptr@ios@@IAEPAU_CRT_CRITICAL_SECTION@@XZ */
2155 /* ?lockptr@ios@@IEAAPEAU_CRT_CRITICAL_SECTION@@XZ */
2156 DEFINE_THISCALL_WRAPPER(ios_lockptr, 4)
2157 CRITICAL_SECTION* __thiscall ios_lockptr(ios *this)
2159 TRACE("(%p)\n", this);
2160 return &this->lock;
2163 /* ?oct@@YAAAVios@@AAV1@@Z */
2164 /* ?oct@@YAAEAVios@@AEAV1@@Z */
2165 ios* __cdecl ios_oct(ios *this)
2167 TRACE("(%p)\n", this);
2168 ios_setf_mask(this, FLAGS_oct, ios_basefield);
2169 return this;
2172 /* ?precision@ios@@QAEHH@Z */
2173 /* ?precision@ios@@QEAAHH@Z */
2174 DEFINE_THISCALL_WRAPPER(ios_precision_set, 8)
2175 int __thiscall ios_precision_set(ios *this, int prec)
2177 int prev = this->precision;
2179 TRACE("(%p %d)\n", this, prec);
2181 this->precision = prec;
2182 return prev;
2185 /* ?precision@ios@@QBEHXZ */
2186 /* ?precision@ios@@QEBAHXZ */
2187 DEFINE_THISCALL_WRAPPER(ios_precision_get, 4)
2188 int __thiscall ios_precision_get(const ios *this)
2190 TRACE("(%p)\n", this);
2191 return this->precision;
2194 /* ?pword@ios@@QBEAAPAXH@Z */
2195 /* ?pword@ios@@QEBAAEAPEAXH@Z */
2196 DEFINE_THISCALL_WRAPPER(ios_pword, 8)
2197 void** __thiscall ios_pword(const ios *this, int index)
2199 TRACE("(%p %d)\n", this, index);
2200 return (void**)&ios_statebuf[index];
2203 /* ?rdbuf@ios@@QBEPAVstreambuf@@XZ */
2204 /* ?rdbuf@ios@@QEBAPEAVstreambuf@@XZ */
2205 DEFINE_THISCALL_WRAPPER(ios_rdbuf, 4)
2206 streambuf* __thiscall ios_rdbuf(const ios *this)
2208 TRACE("(%p)\n", this);
2209 return this->sb;
2212 /* ?rdstate@ios@@QBEHXZ */
2213 /* ?rdstate@ios@@QEBAHXZ */
2214 DEFINE_THISCALL_WRAPPER(ios_rdstate, 4)
2215 int __thiscall ios_rdstate(const ios *this)
2217 TRACE("(%p)\n", this);
2218 return this->state;
2221 /* ?setf@ios@@QAEJJ@Z */
2222 /* ?setf@ios@@QEAAJJ@Z */
2223 DEFINE_THISCALL_WRAPPER(ios_setf, 8)
2224 LONG __thiscall ios_setf(ios *this, LONG flags)
2226 LONG prev = this->flags;
2228 TRACE("(%p %lx)\n", this, flags);
2230 ios_lock(this);
2231 this->flags |= flags;
2232 ios_unlock(this);
2233 return prev;
2236 /* ?setf@ios@@QAEJJJ@Z */
2237 /* ?setf@ios@@QEAAJJJ@Z */
2238 DEFINE_THISCALL_WRAPPER(ios_setf_mask, 12)
2239 LONG __thiscall ios_setf_mask(ios *this, LONG flags, LONG mask)
2241 LONG prev = this->flags;
2243 TRACE("(%p %lx %lx)\n", this, flags, mask);
2245 ios_lock(this);
2246 this->flags = (this->flags & (~mask)) | (flags & mask);
2247 ios_unlock(this);
2248 return prev;
2251 /* ?setlock@ios@@QAAXXZ */
2252 /* ?setlock@ios@@QEAAXXZ */
2253 void __cdecl ios_setlock(ios *this)
2255 TRACE("(%p)\n", this);
2256 this->do_lock--;
2257 if (this->sb)
2258 streambuf_setlock(this->sb);
2261 /* ?tie@ios@@QAEPAVostream@@PAV2@@Z */
2262 /* ?tie@ios@@QEAAPEAVostream@@PEAV2@@Z */
2263 DEFINE_THISCALL_WRAPPER(ios_tie_set, 8)
2264 ostream* __thiscall ios_tie_set(ios *this, ostream *ostr)
2266 ostream *prev = this->tie;
2268 TRACE("(%p %p)\n", this, ostr);
2270 this->tie = ostr;
2271 return prev;
2274 /* ?tie@ios@@QBEPAVostream@@XZ */
2275 /* ?tie@ios@@QEBAPEAVostream@@XZ */
2276 DEFINE_THISCALL_WRAPPER(ios_tie_get, 4)
2277 ostream* __thiscall ios_tie_get(const ios *this)
2279 TRACE("(%p)\n", this);
2280 return this->tie;
2283 /* ?unlock@ios@@QAAXXZ */
2284 /* ?unlock@ios@@QEAAXXZ */
2285 void __cdecl ios_unlock(ios *this)
2287 TRACE("(%p)\n", this);
2288 if (this->do_lock < 0)
2289 LeaveCriticalSection(&this->lock);
2292 /* ?unlockbuf@ios@@QAAXXZ */
2293 /* ?unlockbuf@ios@@QEAAXXZ */
2294 void __cdecl ios_unlockbuf(ios *this)
2296 TRACE("(%p)\n", this);
2297 streambuf_unlock(this->sb);
2300 /* ?unlockc@ios@@KAXXZ */
2301 void __cdecl ios_unlockc(void)
2303 TRACE("()\n");
2304 LeaveCriticalSection(&ios_static_lock);
2307 /* ?unsetf@ios@@QAEJJ@Z */
2308 /* ?unsetf@ios@@QEAAJJ@Z */
2309 DEFINE_THISCALL_WRAPPER(ios_unsetf, 8)
2310 LONG __thiscall ios_unsetf(ios *this, LONG flags)
2312 LONG prev = this->flags;
2314 TRACE("(%p %lx)\n", this, flags);
2316 ios_lock(this);
2317 this->flags &= ~flags;
2318 ios_unlock(this);
2319 return prev;
2322 /* ?width@ios@@QAEHH@Z */
2323 /* ?width@ios@@QEAAHH@Z */
2324 DEFINE_THISCALL_WRAPPER(ios_width_set, 8)
2325 int __thiscall ios_width_set(ios *this, int width)
2327 int prev = this->width;
2329 TRACE("(%p %d)\n", this, width);
2331 this->width = width;
2332 return prev;
2335 /* ?width@ios@@QBEHXZ */
2336 /* ?width@ios@@QEBAHXZ */
2337 DEFINE_THISCALL_WRAPPER(ios_width_get, 4)
2338 int __thiscall ios_width_get(const ios *this)
2340 TRACE("(%p)\n", this);
2341 return this->width;
2344 /* ?xalloc@ios@@SAHXZ */
2345 int __cdecl ios_xalloc(void)
2347 int ret;
2349 TRACE("()\n");
2351 ios_lockc();
2352 ret = (ios_curindex < STATEBUF_SIZE-1) ? ++ios_curindex : -1;
2353 ios_unlockc();
2354 return ret;
2357 static inline ios* ostream_get_ios(const ostream *this)
2359 return (ios*)((char*)this + this->vbtable[1]);
2362 static inline ios* ostream_to_ios(const ostream *this)
2364 return (ios*)((char*)this + ostream_vbtable[1]);
2367 static inline ostream* ios_to_ostream(const ios *base)
2369 return (ostream*)((char*)base - ostream_vbtable[1]);
2372 /* ??0ostream@@IAE@XZ */
2373 /* ??0ostream@@IEAA@XZ */
2374 DEFINE_THISCALL_WRAPPER(ostream_ctor, 8)
2375 ostream* __thiscall ostream_ctor(ostream *this, BOOL virt_init)
2377 ios *base;
2379 TRACE("(%p %d)\n", this, virt_init);
2381 if (virt_init) {
2382 this->vbtable = ostream_vbtable;
2383 base = ostream_get_ios(this);
2384 ios_ctor(base);
2385 } else
2386 base = ostream_get_ios(this);
2387 base->vtable = &ostream_vtable;
2388 this->unknown = 0;
2389 return this;
2392 /* ??0ostream@@QAE@PAVstreambuf@@@Z */
2393 /* ??0ostream@@QEAA@PEAVstreambuf@@@Z */
2394 DEFINE_THISCALL_WRAPPER(ostream_sb_ctor, 12)
2395 ostream* __thiscall ostream_sb_ctor(ostream *this, streambuf *sb, BOOL virt_init)
2397 TRACE("(%p %p %d)\n", this, sb, virt_init);
2398 ostream_ctor(this, virt_init);
2399 ios_init(ostream_get_ios(this), sb);
2400 return this;
2403 /* ??0ostream@@IAE@ABV0@@Z */
2404 /* ??0ostream@@IEAA@AEBV0@@Z */
2405 DEFINE_THISCALL_WRAPPER(ostream_copy_ctor, 12)
2406 ostream* __thiscall ostream_copy_ctor(ostream *this, const ostream *copy, BOOL virt_init)
2408 return ostream_sb_ctor(this, ostream_get_ios(copy)->sb, virt_init);
2411 /* ??1ostream@@UAE@XZ */
2412 /* ??1ostream@@UEAA@XZ */
2413 /* ??1ostream_withassign@@UAE@XZ */
2414 /* ??1ostream_withassign@@UEAA@XZ */
2415 /* ??1ostrstream@@UAE@XZ */
2416 /* ??1ostrstream@@UEAA@XZ */
2417 /* ??1ofstream@@UAE@XZ */
2418 /* ??1ofstream@@UEAA@XZ */
2419 DEFINE_THISCALL_WRAPPER(ostream_dtor, 4)
2420 void __thiscall ostream_dtor(ios *base)
2422 ostream *this = ios_to_ostream(base);
2424 TRACE("(%p)\n", this);
2427 /* ??4ostream@@IAEAAV0@PAVstreambuf@@@Z */
2428 /* ??4ostream@@IEAAAEAV0@PEAVstreambuf@@@Z */
2429 /* ??4ostream_withassign@@QAEAAVostream@@PAVstreambuf@@@Z */
2430 /* ??4ostream_withassign@@QEAAAEAVostream@@PEAVstreambuf@@@Z */
2431 DEFINE_THISCALL_WRAPPER(ostream_assign_sb, 8)
2432 ostream* __thiscall ostream_assign_sb(ostream *this, streambuf *sb)
2434 ios *base = ostream_get_ios(this);
2436 TRACE("(%p %p)\n", this, sb);
2438 ios_init(base, sb);
2439 base->state &= IOSTATE_badbit;
2440 base->delbuf = 0;
2441 base->tie = NULL;
2442 base->flags = 0;
2443 base->precision = 6;
2444 base->fill = ' ';
2445 base->width = 0;
2446 return this;
2449 /* ??4ostream@@IAEAAV0@ABV0@@Z */
2450 /* ??4ostream@@IEAAAEAV0@AEBV0@@Z */
2451 /* ??4ostream_withassign@@QAEAAV0@ABV0@@Z */
2452 /* ??4ostream_withassign@@QEAAAEAV0@AEBV0@@Z */
2453 /* ??4ostream_withassign@@QAEAAVostream@@ABV1@@Z */
2454 /* ??4ostream_withassign@@QEAAAEAVostream@@AEBV1@@Z */
2455 /* ??4ostrstream@@QAEAAV0@ABV0@@Z */
2456 /* ??4ostrstream@@QEAAAEAV0@AEBV0@@Z */
2457 /* ??4ofstream@@QAEAAV0@ABV0@@Z */
2458 /* ??4ofstream@@QEAAAEAV0@AEBV0@@Z */
2459 DEFINE_THISCALL_WRAPPER(ostream_assign, 8)
2460 ostream* __thiscall ostream_assign(ostream *this, const ostream *rhs)
2462 return ostream_assign_sb(this, ostream_get_ios(rhs)->sb);
2465 /* ??_Dostream@@QAEXXZ */
2466 /* ??_Dostream@@QEAAXXZ */
2467 /* ??_Dostream_withassign@@QAEXXZ */
2468 /* ??_Dostream_withassign@@QEAAXXZ */
2469 /* ??_Dostrstream@@QAEXXZ */
2470 /* ??_Dostrstream@@QEAAXXZ */
2471 /* ??_Dofstream@@QAEXXZ */
2472 /* ??_Dofstream@@QEAAXXZ */
2473 DEFINE_THISCALL_WRAPPER(ostream_vbase_dtor, 4)
2474 void __thiscall ostream_vbase_dtor(ostream *this)
2476 ios *base = ostream_to_ios(this);
2478 TRACE("(%p)\n", this);
2480 ostream_dtor(base);
2481 ios_dtor(base);
2484 /* ??_Eostream@@UAEPAXI@Z */
2485 /* ??_Eostream_withassign@@UAEPAXI@Z */
2486 /* ??_Eostrstream@@UAEPAXI@Z */
2487 /* ??_Eofstream@@UAEPAXI@Z */
2488 DEFINE_THISCALL_WRAPPER(ostream_vector_dtor, 8)
2489 ostream* __thiscall ostream_vector_dtor(ios *base, unsigned int flags)
2491 ostream *this = ios_to_ostream(base);
2493 TRACE("(%p %x)\n", this, flags);
2495 if (flags & 2) {
2496 /* we have an array, with the number of elements stored before the first object */
2497 INT_PTR i, *ptr = (INT_PTR *)this-1;
2499 for (i = *ptr-1; i >= 0; i--)
2500 ostream_vbase_dtor(this+i);
2501 operator_delete(ptr);
2502 } else {
2503 ostream_vbase_dtor(this);
2504 if (flags & 1)
2505 operator_delete(this);
2507 return this;
2510 /* ??_Gostream@@UAEPAXI@Z */
2511 /* ??_Gostream_withassign@@UAEPAXI@Z */
2512 /* ??_Gostrstream@@UAEPAXI@Z */
2513 /* ??_Gofstream@@UAEPAXI@Z */
2514 DEFINE_THISCALL_WRAPPER(ostream_scalar_dtor, 8)
2515 ostream* __thiscall ostream_scalar_dtor(ios *base, unsigned int flags)
2517 ostream *this = ios_to_ostream(base);
2519 TRACE("(%p %x)\n", this, flags);
2521 ostream_vbase_dtor(this);
2522 if (flags & 1) operator_delete(this);
2523 return this;
2526 /* ?flush@ostream@@QAEAAV1@XZ */
2527 /* ?flush@ostream@@QEAAAEAV1@XZ */
2528 DEFINE_THISCALL_WRAPPER(ostream_flush, 4)
2529 ostream* __thiscall ostream_flush(ostream *this)
2531 ios *base = ostream_get_ios(this);
2533 TRACE("(%p)\n", this);
2535 ios_lockbuf(base);
2536 if (call_streambuf_sync(base->sb) == EOF)
2537 ios_clear(base, base->state | IOSTATE_failbit);
2538 ios_unlockbuf(base);
2539 return this;
2542 /* ?opfx@ostream@@QAEHXZ */
2543 /* ?opfx@ostream@@QEAAHXZ */
2544 DEFINE_THISCALL_WRAPPER(ostream_opfx, 4)
2545 int __thiscall ostream_opfx(ostream *this)
2547 ios *base = ostream_get_ios(this);
2549 TRACE("(%p)\n", this);
2551 if (!ios_good(base)) {
2552 ios_clear(base, base->state | IOSTATE_failbit);
2553 return 0;
2555 ios_lock(base);
2556 ios_lockbuf(base);
2557 if (base->tie)
2558 ostream_flush(base->tie);
2559 return 1;
2562 /* ?osfx@ostream@@QAEXXZ */
2563 /* ?osfx@ostream@@QEAAXXZ */
2564 DEFINE_THISCALL_WRAPPER(ostream_osfx, 4)
2565 void __thiscall ostream_osfx(ostream *this)
2567 ios *base = ostream_get_ios(this);
2569 TRACE("(%p)\n", this);
2571 ios_unlockbuf(base);
2572 ios_width_set(base, 0);
2573 if (base->flags & FLAGS_unitbuf)
2574 ostream_flush(this);
2575 if (base->flags & FLAGS_stdio) {
2576 fflush(stdout);
2577 fflush(stderr);
2579 ios_unlock(base);
2582 /* ?put@ostream@@QAEAAV1@C@Z */
2583 /* ?put@ostream@@QEAAAEAV1@C@Z */
2584 /* ?put@ostream@@QAEAAV1@D@Z */
2585 /* ?put@ostream@@QEAAAEAV1@D@Z */
2586 /* ?put@ostream@@QAEAAV1@E@Z */
2587 /* ?put@ostream@@QEAAAEAV1@E@Z */
2588 DEFINE_THISCALL_WRAPPER(ostream_put, 8)
2589 ostream* __thiscall ostream_put(ostream *this, char c)
2591 ios *base = ostream_get_ios(this);
2593 TRACE("(%p %c)\n", this, c);
2595 if (ostream_opfx(this)) {
2596 if (streambuf_sputc(base->sb, c) == EOF)
2597 base->state = IOSTATE_badbit | IOSTATE_failbit;
2598 ostream_osfx(this);
2600 return this;
2603 /* ?seekp@ostream@@QAEAAV1@J@Z */
2604 /* ?seekp@ostream@@QEAAAEAV1@J@Z */
2605 DEFINE_THISCALL_WRAPPER(ostream_seekp, 8)
2606 ostream* __thiscall ostream_seekp(ostream *this, streampos pos)
2608 ios *base = ostream_get_ios(this);
2610 TRACE("(%p %ld)\n", this, pos);
2612 ios_lockbuf(base);
2613 if (streambuf_seekpos(base->sb, pos, OPENMODE_out) == EOF)
2614 ios_clear(base, base->state | IOSTATE_failbit);
2615 ios_unlockbuf(base);
2616 return this;
2619 /* ?seekp@ostream@@QAEAAV1@JW4seek_dir@ios@@@Z */
2620 /* ?seekp@ostream@@QEAAAEAV1@JW4seek_dir@ios@@@Z */
2621 DEFINE_THISCALL_WRAPPER(ostream_seekp_offset, 12)
2622 ostream* __thiscall ostream_seekp_offset(ostream *this, streamoff off, ios_seek_dir dir)
2624 ios *base = ostream_get_ios(this);
2626 TRACE("(%p %ld %d)\n", this, off, dir);
2628 ios_lockbuf(base);
2629 if (call_streambuf_seekoff(base->sb, off, dir, OPENMODE_out) == EOF)
2630 ios_clear(base, base->state | IOSTATE_failbit);
2631 ios_unlockbuf(base);
2632 return this;
2635 /* ?tellp@ostream@@QAEJXZ */
2636 /* ?tellp@ostream@@QEAAJXZ */
2637 DEFINE_THISCALL_WRAPPER(ostream_tellp, 4)
2638 streampos __thiscall ostream_tellp(ostream *this)
2640 ios *base = ostream_get_ios(this);
2641 streampos pos;
2643 TRACE("(%p)\n", this);
2645 ios_lockbuf(base);
2646 if ((pos = call_streambuf_seekoff(base->sb, 0, SEEKDIR_cur, OPENMODE_out)) == EOF)
2647 ios_clear(base, base->state | IOSTATE_failbit);
2648 ios_unlockbuf(base);
2649 return pos;
2652 /* ?write@ostream@@QAEAAV1@PBCH@Z */
2653 /* ?write@ostream@@QEAAAEAV1@PEBCH@Z */
2654 /* ?write@ostream@@QAEAAV1@PBDH@Z */
2655 /* ?write@ostream@@QEAAAEAV1@PEBDH@Z */
2656 /* ?write@ostream@@QAEAAV1@PBEH@Z */
2657 /* ?write@ostream@@QEAAAEAV1@PEBEH@Z */
2658 DEFINE_THISCALL_WRAPPER(ostream_write, 12)
2659 ostream* __thiscall ostream_write(ostream *this, const char *str, int count)
2661 ios *base = ostream_get_ios(this);
2663 TRACE("(%p %p %d)\n", this, str, count);
2665 if (ostream_opfx(this)) {
2666 if (streambuf_sputn(base->sb, str, count) != count)
2667 base->state = IOSTATE_badbit | IOSTATE_failbit;
2668 ostream_osfx(this);
2670 return this;
2673 /* ?writepad@ostream@@AAEAAV1@PBD0@Z */
2674 /* ?writepad@ostream@@AEAAAEAV1@PEBD0@Z */
2675 DEFINE_THISCALL_WRAPPER(ostream_writepad, 12)
2676 ostream* __thiscall ostream_writepad(ostream *this, const char *str1, const char *str2)
2678 ios *base = ostream_get_ios(this);
2679 int len1 = strlen(str1), len2 = strlen(str2), i;
2681 TRACE("(%p %p %p)\n", this, str1, str2);
2683 /* left of the padding */
2684 if (base->flags & (FLAGS_left|FLAGS_internal)) {
2685 if (streambuf_sputn(base->sb, str1, len1) != len1)
2686 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2687 if (!(base->flags & FLAGS_internal))
2688 if (streambuf_sputn(base->sb, str2, len2) != len2)
2689 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2691 /* add padding to fill the width */
2692 for (i = len1 + len2; i < base->width; i++)
2693 if (streambuf_sputc(base->sb, base->fill) == EOF)
2694 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2695 /* right of the padding */
2696 if ((base->flags & (FLAGS_left|FLAGS_internal)) != FLAGS_left) {
2697 if (!(base->flags & (FLAGS_left|FLAGS_internal)))
2698 if (streambuf_sputn(base->sb, str1, len1) != len1)
2699 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2700 if (streambuf_sputn(base->sb, str2, len2) != len2)
2701 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2703 return this;
2706 static ostream* ostream_internal_print_integer(ostream *ostr, int n, BOOL unsig, BOOL shrt)
2708 ios *base = ostream_get_ios(ostr);
2709 char prefix_str[3] = {0}, number_str[12], sprintf_fmt[4] = {'%','d',0};
2711 TRACE("(%p %d %d %d)\n", ostr, n, unsig, shrt);
2713 if (ostream_opfx(ostr)) {
2714 if (base->flags & FLAGS_hex) {
2715 sprintf_fmt[1] = (base->flags & FLAGS_uppercase) ? 'X' : 'x';
2716 if (base->flags & FLAGS_showbase) {
2717 prefix_str[0] = '0';
2718 prefix_str[1] = (base->flags & FLAGS_uppercase) ? 'X' : 'x';
2720 } else if (base->flags & FLAGS_oct) {
2721 sprintf_fmt[1] = 'o';
2722 if (base->flags & FLAGS_showbase)
2723 prefix_str[0] = '0';
2724 } else { /* FLAGS_dec */
2725 if (unsig)
2726 sprintf_fmt[1] = 'u';
2727 if ((base->flags & FLAGS_showpos) && n != 0 && (unsig || n > 0))
2728 prefix_str[0] = '+';
2731 if (shrt) {
2732 sprintf_fmt[2] = sprintf_fmt[1];
2733 sprintf_fmt[1] = 'h';
2736 if (sprintf(number_str, sprintf_fmt, n) > 0)
2737 ostream_writepad(ostr, prefix_str, number_str);
2738 else
2739 base->state |= IOSTATE_failbit;
2740 ostream_osfx(ostr);
2742 return ostr;
2745 static ostream* ostream_internal_print_float(ostream *ostr, double d, BOOL dbl)
2747 ios *base = ostream_get_ios(ostr);
2748 char prefix_str[2] = {0}, number_str[24], sprintf_fmt[6] = {'%','.','*','f',0};
2749 int prec, max_prec = dbl ? 15 : 6;
2750 int str_length = 1; /* null end char */
2752 TRACE("(%p %lf %d)\n", ostr, d, dbl);
2754 if (ostream_opfx(ostr)) {
2755 if ((base->flags & FLAGS_showpos) && d > 0) {
2756 prefix_str[0] = '+';
2757 str_length++; /* plus sign */
2759 if ((base->flags & (FLAGS_scientific|FLAGS_fixed)) == FLAGS_scientific)
2760 sprintf_fmt[3] = (base->flags & FLAGS_uppercase) ? 'E' : 'e';
2761 else if ((base->flags & (FLAGS_scientific|FLAGS_fixed)) != FLAGS_fixed)
2762 sprintf_fmt[3] = (base->flags & FLAGS_uppercase) ? 'G' : 'g';
2763 if (base->flags & FLAGS_showpoint) {
2764 sprintf_fmt[4] = sprintf_fmt[3];
2765 sprintf_fmt[3] = sprintf_fmt[2];
2766 sprintf_fmt[2] = sprintf_fmt[1];
2767 sprintf_fmt[1] = '#';
2770 prec = (base->precision >= 0 && base->precision <= max_prec) ? base->precision : max_prec;
2771 str_length += _scprintf(sprintf_fmt, prec, d); /* number representation */
2772 if (str_length > 24) {
2773 /* when the output length exceeds 24 characters, Windows prints an empty string with padding */
2774 ostream_writepad(ostr, "", "");
2775 } else {
2776 if (sprintf(number_str, sprintf_fmt, prec, d) > 0)
2777 ostream_writepad(ostr, prefix_str, number_str);
2778 else
2779 base->state |= IOSTATE_failbit;
2781 ostream_osfx(ostr);
2783 return ostr;
2786 /* ??6ostream@@QAEAAV0@C@Z */
2787 /* ??6ostream@@QEAAAEAV0@C@Z */
2788 /* ??6ostream@@QAEAAV0@D@Z */
2789 /* ??6ostream@@QEAAAEAV0@D@Z */
2790 /* ??6ostream@@QAEAAV0@E@Z */
2791 /* ??6ostream@@QEAAAEAV0@E@Z */
2792 DEFINE_THISCALL_WRAPPER(ostream_print_char, 8)
2793 ostream* __thiscall ostream_print_char(ostream *this, char c)
2795 const char c_str[2] = {c, 0};
2797 TRACE("(%p %c)\n", this, c);
2799 if (ostream_opfx(this)) {
2800 ostream_writepad(this, "", c_str);
2801 ostream_osfx(this);
2803 return this;
2806 /* ??6ostream@@QAEAAV0@PBC@Z */
2807 /* ??6ostream@@QEAAAEAV0@PEBC@Z */
2808 /* ??6ostream@@QAEAAV0@PBD@Z */
2809 /* ??6ostream@@QEAAAEAV0@PEBD@Z */
2810 /* ??6ostream@@QAEAAV0@PBE@Z */
2811 /* ??6ostream@@QEAAAEAV0@PEBE@Z */
2812 DEFINE_THISCALL_WRAPPER(ostream_print_str, 8)
2813 ostream* __thiscall ostream_print_str(ostream *this, const char *str)
2815 TRACE("(%p %s)\n", this, str);
2816 if (ostream_opfx(this)) {
2817 ostream_writepad(this, "", str);
2818 ostream_osfx(this);
2820 return this;
2823 /* ??6ostream@@QAEAAV0@F@Z */
2824 /* ??6ostream@@QEAAAEAV0@F@Z */
2825 DEFINE_THISCALL_WRAPPER(ostream_print_short, 8)
2826 ostream* __thiscall ostream_print_short(ostream *this, short n)
2828 return ostream_internal_print_integer(this, n, FALSE, TRUE);
2831 /* ??6ostream@@QAEAAV0@G@Z */
2832 /* ??6ostream@@QEAAAEAV0@G@Z */
2833 DEFINE_THISCALL_WRAPPER(ostream_print_unsigned_short, 8)
2834 ostream* __thiscall ostream_print_unsigned_short(ostream *this, unsigned short n)
2836 return ostream_internal_print_integer(this, n, TRUE, TRUE);
2839 /* ??6ostream@@QAEAAV0@H@Z */
2840 /* ??6ostream@@QEAAAEAV0@H@Z */
2841 /* ??6ostream@@QAEAAV0@J@Z */
2842 /* ??6ostream@@QEAAAEAV0@J@Z */
2843 DEFINE_THISCALL_WRAPPER(ostream_print_int, 8)
2844 ostream* __thiscall ostream_print_int(ostream *this, int n)
2846 return ostream_internal_print_integer(this, n, FALSE, FALSE);
2849 /* ??6ostream@@QAEAAV0@I@Z */
2850 /* ??6ostream@@QEAAAEAV0@I@Z */
2851 /* ??6ostream@@QAEAAV0@K@Z */
2852 /* ??6ostream@@QEAAAEAV0@K@Z */
2853 DEFINE_THISCALL_WRAPPER(ostream_print_unsigned_int, 8)
2854 ostream* __thiscall ostream_print_unsigned_int(ostream *this, unsigned int n)
2856 return ostream_internal_print_integer(this, n, TRUE, FALSE);
2859 /* ??6ostream@@QAEAAV0@M@Z */
2860 /* ??6ostream@@QEAAAEAV0@M@Z */
2861 DEFINE_THISCALL_WRAPPER(ostream_print_float, 8)
2862 ostream* __thiscall ostream_print_float(ostream *this, float f)
2864 return ostream_internal_print_float(this, f, FALSE);
2867 /* ??6ostream@@QAEAAV0@N@Z */
2868 /* ??6ostream@@QEAAAEAV0@N@Z */
2869 /* ??6ostream@@QAEAAV0@O@Z */
2870 /* ??6ostream@@QEAAAEAV0@O@Z */
2871 DEFINE_THISCALL_WRAPPER(ostream_print_double, 12)
2872 ostream* __thiscall ostream_print_double(ostream *this, double d)
2874 return ostream_internal_print_float(this, d, TRUE);
2877 /* ??6ostream@@QAEAAV0@PBX@Z */
2878 /* ??6ostream@@QEAAAEAV0@PEBX@Z */
2879 DEFINE_THISCALL_WRAPPER(ostream_print_ptr, 8)
2880 ostream* __thiscall ostream_print_ptr(ostream *this, const void *ptr)
2882 ios *base = ostream_get_ios(this);
2883 char prefix_str[3] = {'0','x',0}, pointer_str[17];
2885 TRACE("(%p %p)\n", this, ptr);
2887 if (ostream_opfx(this)) {
2888 if (ptr && base->flags & FLAGS_uppercase)
2889 prefix_str[1] = 'X';
2891 if (sprintf(pointer_str, "%p", ptr) > 0)
2892 ostream_writepad(this, prefix_str, pointer_str);
2893 else
2894 base->state |= IOSTATE_failbit;
2895 ostream_osfx(this);
2897 return this;
2900 /* ??6ostream@@QAEAAV0@PAVstreambuf@@@Z */
2901 /* ??6ostream@@QEAAAEAV0@PEAVstreambuf@@@Z */
2902 DEFINE_THISCALL_WRAPPER(ostream_print_streambuf, 8)
2903 ostream* __thiscall ostream_print_streambuf(ostream *this, streambuf *sb)
2905 ios *base = ostream_get_ios(this);
2906 int c;
2908 TRACE("(%p %p)\n", this, sb);
2910 if (ostream_opfx(this)) {
2911 while ((c = streambuf_sbumpc(sb)) != EOF) {
2912 if (streambuf_sputc(base->sb, c) == EOF) {
2913 base->state |= IOSTATE_failbit;
2914 break;
2917 ostream_osfx(this);
2919 return this;
2922 /* ??6ostream@@QAEAAV0@P6AAAV0@AAV0@@Z@Z */
2923 /* ??6ostream@@QEAAAEAV0@P6AAEAV0@AEAV0@@Z@Z */
2924 DEFINE_THISCALL_WRAPPER(ostream_print_manip, 8)
2925 ostream* __thiscall ostream_print_manip(ostream *this, ostream* (__cdecl *func)(ostream*))
2927 TRACE("(%p %p)\n", this, func);
2928 return func(this);
2931 /* ??6ostream@@QAEAAV0@P6AAAVios@@AAV1@@Z@Z */
2932 /* ??6ostream@@QEAAAEAV0@P6AAEAVios@@AEAV1@@Z@Z */
2933 DEFINE_THISCALL_WRAPPER(ostream_print_ios_manip, 8)
2934 ostream* __thiscall ostream_print_ios_manip(ostream *this, ios* (__cdecl *func)(ios*))
2936 TRACE("(%p %p)\n", this, func);
2937 func(ostream_get_ios(this));
2938 return this;
2941 /* ?endl@@YAAAVostream@@AAV1@@Z */
2942 /* ?endl@@YAAEAVostream@@AEAV1@@Z */
2943 ostream* __cdecl ostream_endl(ostream *this)
2945 TRACE("(%p)\n", this);
2946 ostream_put(this, '\n');
2947 return ostream_flush(this);
2950 /* ?ends@@YAAAVostream@@AAV1@@Z */
2951 /* ?ends@@YAAEAVostream@@AEAV1@@Z */
2952 ostream* __cdecl ostream_ends(ostream *this)
2954 TRACE("(%p)\n", this);
2955 return ostream_put(this, 0);
2958 /* ?flush@@YAAAVostream@@AAV1@@Z */
2959 /* ?flush@@YAAEAVostream@@AEAV1@@Z */
2960 ostream* __cdecl ostream_flush_manip(ostream *this)
2962 TRACE("(%p)\n", this);
2963 return ostream_flush(this);
2966 /* ??0ostream_withassign@@QAE@ABV0@@Z */
2967 /* ??0ostream_withassign@@QEAA@AEBV0@@Z */
2968 DEFINE_THISCALL_WRAPPER(ostream_withassign_copy_ctor, 12)
2969 ostream* __thiscall ostream_withassign_copy_ctor(ostream *this, const ostream *copy, BOOL virt_init)
2971 ios *base, *base_copy;
2973 TRACE("(%p %p %d)\n", this, copy, virt_init);
2975 base_copy = ostream_get_ios(copy);
2976 if (virt_init) {
2977 this->vbtable = ostream_vbtable;
2978 base = ostream_get_ios(this);
2979 ios_copy_ctor(base, base_copy);
2980 } else
2981 base = ostream_get_ios(this);
2982 ios_init(base, base_copy->sb);
2983 base->vtable = &ostream_withassign_vtable;
2984 this->unknown = 0;
2985 return this;
2988 /* ??0ostream_withassign@@QAE@PAVstreambuf@@@Z */
2989 /* ??0ostream_withassign@@QEAA@PEAVstreambuf@@@Z */
2990 DEFINE_THISCALL_WRAPPER(ostream_withassign_sb_ctor, 12)
2991 ostream* __thiscall ostream_withassign_sb_ctor(ostream *this, streambuf *sb, BOOL virt_init)
2993 ios *base;
2995 TRACE("(%p %p %d)\n", this, sb, virt_init);
2997 ostream_sb_ctor(this, sb, virt_init);
2998 base = ostream_get_ios(this);
2999 base->vtable = &ostream_withassign_vtable;
3000 return this;
3003 /* ??0ostream_withassign@@QAE@XZ */
3004 /* ??0ostream_withassign@@QEAA@XZ */
3005 DEFINE_THISCALL_WRAPPER(ostream_withassign_ctor, 8)
3006 ostream* __thiscall ostream_withassign_ctor(ostream *this, BOOL virt_init)
3008 ios *base;
3010 TRACE("(%p %d)\n", this, virt_init);
3012 ostream_ctor(this, virt_init);
3013 base = ostream_get_ios(this);
3014 base->vtable = &ostream_withassign_vtable;
3015 return this;
3018 static ostream* ostrstream_internal_sb_ctor(ostream *this, strstreambuf *ssb, BOOL virt_init)
3020 ios *base;
3022 if (ssb)
3023 ostream_sb_ctor(this, &ssb->base, virt_init);
3024 else
3025 ostream_ctor(this, virt_init);
3026 base = ostream_get_ios(this);
3027 base->vtable = &ostrstream_vtable;
3028 base->delbuf = 1;
3029 return this;
3032 /* ??0ostrstream@@QAE@ABV0@@Z */
3033 /* ??0ostrstream@@QEAA@AEBV0@@Z */
3034 DEFINE_THISCALL_WRAPPER(ostrstream_copy_ctor, 12)
3035 ostream* __thiscall ostrstream_copy_ctor(ostream *this, const ostream *copy, BOOL virt_init)
3037 TRACE("(%p %p %d)\n", this, copy, virt_init);
3038 ostream_withassign_copy_ctor(this, copy, virt_init);
3039 ostream_get_ios(this)->vtable = &ostrstream_vtable;
3040 return this;
3043 /* ??0ostrstream@@QAE@PADHH@Z */
3044 /* ??0ostrstream@@QEAA@PEADHH@Z */
3045 DEFINE_THISCALL_WRAPPER(ostrstream_buffer_ctor, 20)
3046 ostream* __thiscall ostrstream_buffer_ctor(ostream *this, char *buffer, int length, int mode, BOOL virt_init)
3048 strstreambuf *ssb = operator_new(sizeof(strstreambuf));
3050 TRACE("(%p %p %d %d %d)\n", this, buffer, length, mode, virt_init);
3052 if (!ssb) {
3053 FIXME("out of memory\n");
3054 return NULL;
3057 strstreambuf_buffer_ctor(ssb, buffer, length, buffer);
3058 if (mode & (OPENMODE_app|OPENMODE_ate))
3059 ssb->base.pptr = buffer + strlen(buffer);
3061 return ostrstream_internal_sb_ctor(this, ssb, virt_init);
3064 /* ??0ostrstream@@QAE@XZ */
3065 /* ??0ostrstream@@QEAA@XZ */
3066 DEFINE_THISCALL_WRAPPER(ostrstream_ctor, 8)
3067 ostream* __thiscall ostrstream_ctor(ostream *this, BOOL virt_init)
3069 strstreambuf *ssb = operator_new(sizeof(strstreambuf));
3071 TRACE("(%p %d)\n", this, virt_init);
3073 if (!ssb) {
3074 FIXME("out of memory\n");
3075 return NULL;
3078 strstreambuf_ctor(ssb);
3080 return ostrstream_internal_sb_ctor(this, ssb, virt_init);
3083 /* ?pcount@ostrstream@@QBEHXZ */
3084 /* ?pcount@ostrstream@@QEBAHXZ */
3085 DEFINE_THISCALL_WRAPPER(ostrstream_pcount, 4)
3086 int __thiscall ostrstream_pcount(const ostream *this)
3088 return streambuf_out_waiting(ostream_get_ios(this)->sb);
3091 /* ?rdbuf@ostrstream@@QBEPAVstrstreambuf@@XZ */
3092 /* ?rdbuf@ostrstream@@QEBAPEAVstrstreambuf@@XZ */
3093 DEFINE_THISCALL_WRAPPER(ostrstream_rdbuf, 4)
3094 strstreambuf* __thiscall ostrstream_rdbuf(const ostream *this)
3096 return (strstreambuf*) ostream_get_ios(this)->sb;
3099 /* ?str@ostrstream@@QAEPADXZ */
3100 /* ?str@ostrstream@@QEAAPEADXZ */
3101 DEFINE_THISCALL_WRAPPER(ostrstream_str, 4)
3102 char* __thiscall ostrstream_str(ostream *this)
3104 return strstreambuf_str(ostrstream_rdbuf(this));
3107 /* ??0ofstream@@QAE@ABV0@@Z */
3108 /* ??0ofstream@@QEAA@AEBV0@@Z */
3109 DEFINE_THISCALL_WRAPPER(ofstream_copy_ctor, 12)
3110 ostream* __thiscall ofstream_copy_ctor(ostream *this, const ostream *copy, BOOL virt_init)
3112 TRACE("(%p %p %d)\n", this, copy, virt_init);
3113 ostream_withassign_copy_ctor(this, copy, virt_init);
3114 ostream_get_ios(this)->vtable = &ofstream_vtable;
3115 return this;
3118 /* ??0ofstream@@QAE@HPADH@Z */
3119 /* ??0ofstream@@QEAA@HPEADH@Z */
3120 DEFINE_THISCALL_WRAPPER(ofstream_buffer_ctor, 20)
3121 ostream* __thiscall ofstream_buffer_ctor(ostream *this, filedesc fd, char *buffer, int length, BOOL virt_init)
3123 ios *base;
3124 filebuf *fb = operator_new(sizeof(filebuf));
3126 TRACE("(%p %d %p %d %d)\n", this, fd, buffer, length, virt_init);
3128 if (!fb) {
3129 FIXME("out of memory\n");
3130 return NULL;
3133 filebuf_fd_reserve_ctor(fb, fd, buffer, length);
3134 ostream_sb_ctor(this, &fb->base, virt_init);
3136 base = ostream_get_ios(this);
3137 base->vtable = &ofstream_vtable;
3138 base->delbuf = 1;
3140 return this;
3143 /* ??0ofstream@@QAE@H@Z */
3144 /* ??0ofstream@@QEAA@H@Z */
3145 DEFINE_THISCALL_WRAPPER(ofstream_fd_ctor, 12)
3146 ostream* __thiscall ofstream_fd_ctor(ostream *this, filedesc fd, BOOL virt_init)
3148 ios *base;
3149 filebuf *fb = operator_new(sizeof(filebuf));
3151 TRACE("(%p %d %d)\n", this, fd, virt_init);
3153 if (!fb) {
3154 FIXME("out of memory\n");
3155 return NULL;
3158 filebuf_fd_ctor(fb, fd);
3159 ostream_sb_ctor(this, &fb->base, virt_init);
3161 base = ostream_get_ios(this);
3162 base->vtable = &ofstream_vtable;
3163 base->delbuf = 1;
3165 return this;
3168 /* ??0ofstream@@QAE@PBDHH@Z */
3169 /* ??0ofstream@@QEAA@PEBDHH@Z */
3170 DEFINE_THISCALL_WRAPPER(ofstream_open_ctor, 20)
3171 ostream* __thiscall ofstream_open_ctor(ostream *this, const char *name, int mode, int protection, BOOL virt_init)
3173 ios *base;
3174 filebuf *fb = operator_new(sizeof(filebuf));
3176 TRACE("(%p %s %d %d %d)\n", this, name, mode, protection, virt_init);
3178 if (!fb) {
3179 FIXME("out of memory\n");
3180 return NULL;
3183 filebuf_ctor(fb);
3184 ostream_sb_ctor(this, &fb->base, virt_init);
3186 base = ostream_get_ios(this);
3187 base->vtable = &ofstream_vtable;
3188 base->delbuf = 1;
3190 if (filebuf_open(fb, name, mode|OPENMODE_out, protection) == NULL)
3191 base->state |= IOSTATE_failbit;
3192 return this;
3195 /* ??0ofstream@@QAE@XZ */
3196 /* ??0ofstream@@QEAA@XZ */
3197 DEFINE_THISCALL_WRAPPER(ofstream_ctor, 8)
3198 ostream* __thiscall ofstream_ctor(ostream *this, BOOL virt_init)
3200 return ofstream_fd_ctor(this, -1, virt_init);
3203 /* ?rdbuf@ofstream@@QBEPAVfilebuf@@XZ */
3204 /* ?rdbuf@ofstream@@QEBAPEAVfilebuf@@XZ */
3205 DEFINE_THISCALL_WRAPPER(ofstream_rdbuf, 4)
3206 filebuf* __thiscall ofstream_rdbuf(const ostream *this)
3208 TRACE("(%p)\n", this);
3209 return (filebuf*) ostream_get_ios(this)->sb;
3212 /* ?fd@ofstream@@QBEHXZ */
3213 /* ?fd@ofstream@@QEBAHXZ */
3214 DEFINE_THISCALL_WRAPPER(ofstream_fd, 4)
3215 filedesc __thiscall ofstream_fd(ostream *this)
3217 TRACE("(%p)\n", this);
3218 return filebuf_fd(ofstream_rdbuf(this));
3221 /* ?attach@ofstream@@QAEXH@Z */
3222 /* ?attach@ofstream@@QEAAXH@Z */
3223 DEFINE_THISCALL_WRAPPER(ofstream_attach, 8)
3224 void __thiscall ofstream_attach(ostream *this, filedesc fd)
3226 ios *base = ostream_get_ios(this);
3227 TRACE("(%p %d)\n", this, fd);
3228 if (filebuf_attach(ofstream_rdbuf(this), fd) == NULL)
3229 ios_clear(base, base->state | IOSTATE_failbit);
3232 /* ?close@ofstream@@QAEXXZ */
3233 /* ?close@ofstream@@QEAAXXZ */
3234 DEFINE_THISCALL_WRAPPER(ofstream_close, 4)
3235 void __thiscall ofstream_close(ostream *this)
3237 ios *base = ostream_get_ios(this);
3238 TRACE("(%p)\n", this);
3239 if (filebuf_close(ofstream_rdbuf(this)) == NULL)
3240 ios_clear(base, base->state | IOSTATE_failbit);
3241 else
3242 ios_clear(base, IOSTATE_goodbit);
3245 /* ?is_open@ofstream@@QBEHXZ */
3246 /* ?is_open@ofstream@@QEBAHXZ */
3247 DEFINE_THISCALL_WRAPPER(ofstream_is_open, 4)
3248 int __thiscall ofstream_is_open(const ostream *this)
3250 TRACE("(%p)\n", this);
3251 return filebuf_is_open(ofstream_rdbuf(this));
3254 /* ?open@ofstream@@QAEXPBDHH@Z */
3255 /* ?open@ofstream@@QEAAXPEBDHH@Z */
3256 DEFINE_THISCALL_WRAPPER(ofstream_open, 16)
3257 void __thiscall ofstream_open(ostream *this, const char *name, ios_open_mode mode, int protection)
3259 ios *base = ostream_get_ios(this);
3260 TRACE("(%p %s %d %d)\n", this, name, mode, protection);
3261 if (filebuf_open(ofstream_rdbuf(this), name, mode|OPENMODE_out, protection) == NULL)
3262 ios_clear(base, base->state | IOSTATE_failbit);
3265 /* ?setbuf@ofstream@@QAEPAVstreambuf@@PADH@Z */
3266 /* ?setbuf@ofstream@@QEAAPEAVstreambuf@@PEADH@Z */
3267 DEFINE_THISCALL_WRAPPER(ofstream_setbuf, 12)
3268 streambuf* __thiscall ofstream_setbuf(ostream *this, char *buffer, int length)
3270 ios *base = ostream_get_ios(this);
3271 filebuf* fb = ofstream_rdbuf(this);
3273 TRACE("(%p %p %d)\n", this, buffer, length);
3275 if (filebuf_is_open(fb)) {
3276 ios_clear(base, base->state | IOSTATE_failbit);
3277 return NULL;
3280 return filebuf_setbuf(fb, buffer, length);
3283 /* ?setmode@ofstream@@QAEHH@Z */
3284 /* ?setmode@ofstream@@QEAAHH@Z */
3285 DEFINE_THISCALL_WRAPPER(ofstream_setmode, 8)
3286 int __thiscall ofstream_setmode(ostream *this, int mode)
3288 TRACE("(%p %d)\n", this, mode);
3289 return filebuf_setmode(ofstream_rdbuf(this), mode);
3292 static inline ios* istream_get_ios(const istream *this)
3294 return (ios*)((char*)this + this->vbtable[1]);
3297 static inline ios* istream_to_ios(const istream *this)
3299 return (ios*)((char*)this + istream_vbtable[1]);
3302 static inline istream* ios_to_istream(const ios *base)
3304 return (istream*)((char*)base - istream_vbtable[1]);
3307 /* ??0istream@@IAE@XZ */
3308 /* ??0istream@@IEAA@XZ */
3309 DEFINE_THISCALL_WRAPPER(istream_ctor, 8)
3310 istream* __thiscall istream_ctor(istream *this, BOOL virt_init)
3312 ios *base;
3314 TRACE("(%p %d)\n", this, virt_init);
3316 if (virt_init) {
3317 this->vbtable = istream_vbtable;
3318 base = istream_get_ios(this);
3319 ios_ctor(base);
3320 } else
3321 base = istream_get_ios(this);
3322 base->vtable = &istream_vtable;
3323 base->flags |= FLAGS_skipws;
3324 this->extract_delim = 0;
3325 this->count = 0;
3326 return this;
3329 /* ??0istream@@QAE@PAVstreambuf@@@Z */
3330 /* ??0istream@@QEAA@PEAVstreambuf@@@Z */
3331 DEFINE_THISCALL_WRAPPER(istream_sb_ctor, 12)
3332 istream* __thiscall istream_sb_ctor(istream *this, streambuf *sb, BOOL virt_init)
3334 TRACE("(%p %p %d)\n", this, sb, virt_init);
3335 istream_ctor(this, virt_init);
3336 ios_init(istream_get_ios(this), sb);
3337 return this;
3340 /* ??0istream@@IAE@ABV0@@Z */
3341 /* ??0istream@@IEAA@AEBV0@@Z */
3342 DEFINE_THISCALL_WRAPPER(istream_copy_ctor, 12)
3343 istream* __thiscall istream_copy_ctor(istream *this, const istream *copy, BOOL virt_init)
3345 return istream_sb_ctor(this, istream_get_ios(copy)->sb, virt_init);
3348 /* ??1istream@@UAE@XZ */
3349 /* ??1istream@@UEAA@XZ */
3350 /* ??1istream_withassign@@UAE@XZ */
3351 /* ??1istream_withassign@@UEAA@XZ */
3352 /* ??1istrstream@@UAE@XZ */
3353 /* ??1istrstream@@UEAA@XZ */
3354 /* ??1ifstream@@UAE@XZ */
3355 /* ??1ifstream@@UEAA@XZ */
3356 DEFINE_THISCALL_WRAPPER(istream_dtor, 4)
3357 void __thiscall istream_dtor(ios *base)
3359 istream *this = ios_to_istream(base);
3361 TRACE("(%p)\n", this);
3364 /* ??4istream@@IAEAAV0@PAVstreambuf@@@Z */
3365 /* ??4istream@@IEAAAEAV0@PEAVstreambuf@@@Z */
3366 /* ??4istream_withassign@@QAEAAVistream@@PAVstreambuf@@@Z */
3367 /* ??4istream_withassign@@QEAAAEAVistream@@PEAVstreambuf@@@Z */
3368 DEFINE_THISCALL_WRAPPER(istream_assign_sb, 8)
3369 istream* __thiscall istream_assign_sb(istream *this, streambuf *sb)
3371 ios *base = istream_get_ios(this);
3373 TRACE("(%p %p)\n", this, sb);
3375 ios_init(base, sb);
3376 base->state &= IOSTATE_badbit;
3377 base->delbuf = 0;
3378 base->tie = NULL;
3379 base->flags = FLAGS_skipws;
3380 base->precision = 6;
3381 base->fill = ' ';
3382 base->width = 0;
3383 this->count = 0;
3384 return this;
3387 /* ??4istream@@IAEAAV0@ABV0@@Z */
3388 /* ??4istream@@IEAAAEAV0@AEBV0@@Z */
3389 /* ??4istream_withassign@@QAEAAV0@ABV0@@Z */
3390 /* ??4istream_withassign@@QEAAAEAV0@AEBV0@@Z */
3391 /* ??4istream_withassign@@QAEAAVistream@@ABV1@@Z */
3392 /* ??4istream_withassign@@QEAAAEAVistream@@AEBV1@@Z */
3393 /* ??4istrstream@@QAEAAV0@ABV0@@Z */
3394 /* ??4istrstream@@QEAAAEAV0@AEBV0@@Z */
3395 /* ??4ifstream@@QAEAAV0@ABV0@@Z */
3396 /* ??4ifstream@@QEAAAEAV0@AEBV0@@Z */
3397 DEFINE_THISCALL_WRAPPER(istream_assign, 8)
3398 istream* __thiscall istream_assign(istream *this, const istream *rhs)
3400 return istream_assign_sb(this, istream_get_ios(rhs)->sb);
3403 /* ??_Distream@@QAEXXZ */
3404 /* ??_Distream@@QEAAXXZ */
3405 /* ??_Distream_withassign@@QAEXXZ */
3406 /* ??_Distream_withassign@@QEAAXXZ */
3407 /* ??_Distrstream@@QAEXXZ */
3408 /* ??_Distrstream@@QEAAXXZ */
3409 /* ??_Difstream@@QAEXXZ */
3410 /* ??_Difstream@@QEAAXXZ */
3411 DEFINE_THISCALL_WRAPPER(istream_vbase_dtor, 4)
3412 void __thiscall istream_vbase_dtor(istream *this)
3414 ios *base = istream_to_ios(this);
3416 TRACE("(%p)\n", this);
3418 istream_dtor(base);
3419 ios_dtor(base);
3422 /* ??_Eistream@@UAEPAXI@Z */
3423 /* ??_Eistream_withassign@@UAEPAXI@Z */
3424 /* ??_Eistrstream@@UAEPAXI@Z */
3425 /* ??_Eifstream@@UAEPAXI@Z */
3426 DEFINE_THISCALL_WRAPPER(istream_vector_dtor, 8)
3427 istream* __thiscall istream_vector_dtor(ios *base, unsigned int flags)
3429 istream *this = ios_to_istream(base);
3431 TRACE("(%p %x)\n", this, flags);
3433 if (flags & 2) {
3434 /* we have an array, with the number of elements stored before the first object */
3435 INT_PTR i, *ptr = (INT_PTR *)this-1;
3437 for (i = *ptr-1; i >= 0; i--)
3438 istream_vbase_dtor(this+i);
3439 operator_delete(ptr);
3440 } else {
3441 istream_vbase_dtor(this);
3442 if (flags & 1)
3443 operator_delete(this);
3445 return this;
3448 /* ??_Gistream@@UAEPAXI@Z */
3449 /* ??_Gistream_withassign@@UAEPAXI@Z */
3450 /* ??_Gistrstream@@UAEPAXI@Z */
3451 /* ??_Gifstream@@UAEPAXI@Z */
3452 DEFINE_THISCALL_WRAPPER(istream_scalar_dtor, 8)
3453 istream* __thiscall istream_scalar_dtor(ios *base, unsigned int flags)
3455 istream *this = ios_to_istream(base);
3457 TRACE("(%p %x)\n", this, flags);
3459 istream_vbase_dtor(this);
3460 if (flags & 1) operator_delete(this);
3461 return this;
3464 /* ?eatwhite@istream@@QAEXXZ */
3465 /* ?eatwhite@istream@@QEAAXXZ */
3466 DEFINE_THISCALL_WRAPPER(istream_eatwhite, 4)
3467 void __thiscall istream_eatwhite(istream *this)
3469 ios *base = istream_get_ios(this);
3470 int c;
3472 TRACE("(%p)\n", this);
3474 ios_lockbuf(base);
3475 for (c = streambuf_sgetc(base->sb); isspace(c); c = streambuf_snextc(base->sb));
3476 ios_unlockbuf(base);
3477 if (c == EOF)
3478 ios_clear(base, base->state | IOSTATE_eofbit);
3481 /* ?gcount@istream@@QBEHXZ */
3482 /* ?gcount@istream@@QEBAHXZ */
3483 DEFINE_THISCALL_WRAPPER(istream_gcount, 4)
3484 int __thiscall istream_gcount(const istream *this)
3486 TRACE("(%p)\n", this);
3487 return this->count;
3490 /* ?ipfx@istream@@QAEHH@Z */
3491 /* ?ipfx@istream@@QEAAHH@Z */
3492 DEFINE_THISCALL_WRAPPER(istream_ipfx, 8)
3493 int __thiscall istream_ipfx(istream *this, int need)
3495 ios *base = istream_get_ios(this);
3497 TRACE("(%p %d)\n", this, need);
3499 if (need)
3500 this->count = 0;
3501 if (!ios_good(base)) {
3502 ios_clear(base, base->state | IOSTATE_failbit);
3503 return 0;
3505 ios_lock(base);
3506 ios_lockbuf(base);
3507 if (base->tie && (!need || streambuf_in_avail(base->sb) < need))
3508 ostream_flush(base->tie);
3509 if ((base->flags & FLAGS_skipws) && !need) {
3510 istream_eatwhite(this);
3511 if (base->state & IOSTATE_eofbit) {
3512 base->state |= IOSTATE_failbit;
3513 ios_unlockbuf(base);
3514 ios_unlock(base);
3515 return 0;
3518 return 1;
3521 /* ?isfx@istream@@QAEXXZ */
3522 /* ?isfx@istream@@QEAAXXZ */
3523 DEFINE_THISCALL_WRAPPER(istream_isfx, 4)
3524 void __thiscall istream_isfx(istream *this)
3526 ios *base = istream_get_ios(this);
3528 TRACE("(%p)\n", this);
3530 ios_unlockbuf(base);
3531 ios_unlock(base);
3534 /* ?get@istream@@IAEAAV1@PADHH@Z */
3535 /* ?get@istream@@IEAAAEAV1@PEADHH@Z */
3536 DEFINE_THISCALL_WRAPPER(istream_get_str_delim, 16)
3537 istream* __thiscall istream_get_str_delim(istream *this, char *str, int count, int delim)
3539 ios *base = istream_get_ios(this);
3540 int ch, i = 0;
3542 TRACE("(%p %p %d %d)\n", this, str, count, delim);
3544 if (istream_ipfx(this, 1)) {
3545 while (i < count - 1) {
3546 if ((ch = streambuf_sgetc(base->sb)) == EOF) {
3547 base->state |= IOSTATE_eofbit;
3548 if (!i) /* tried to read, but not a single character was obtained */
3549 base->state |= IOSTATE_failbit;
3550 break;
3552 if (ch == delim) {
3553 if (this->extract_delim) { /* discard the delimiter */
3554 streambuf_stossc(base->sb);
3555 this->count++;
3557 break;
3559 if (str)
3560 str[i] = ch;
3561 streambuf_stossc(base->sb);
3562 i++;
3564 this->count += i;
3565 istream_isfx(this);
3567 if (str && count) /* append a null terminator, unless a string of 0 characters was requested */
3568 str[i] = 0;
3569 this->extract_delim = 0;
3570 return this;
3573 /* ?get@istream@@QAEAAV1@PACHD@Z */
3574 /* ?get@istream@@QEAAAEAV1@PEACHD@Z */
3575 /* ?get@istream@@QAEAAV1@PADHD@Z */
3576 /* ?get@istream@@QEAAAEAV1@PEADHD@Z */
3577 /* ?get@istream@@QAEAAV1@PAEHD@Z */
3578 /* ?get@istream@@QEAAAEAV1@PEAEHD@Z */
3579 DEFINE_THISCALL_WRAPPER(istream_get_str, 16)
3580 istream* __thiscall istream_get_str(istream *this, char *str, int count, char delim)
3582 return istream_get_str_delim(this, str, count, (unsigned char) delim);
3585 static int istream_internal_get_char(istream *this, char *ch)
3587 ios *base = istream_get_ios(this);
3588 int ret = EOF;
3590 TRACE("(%p %p)\n", this, ch);
3592 if (istream_ipfx(this, 1)) {
3593 if ((ret = streambuf_sbumpc(base->sb)) != EOF) {
3594 this->count = 1;
3595 } else {
3596 base->state |= IOSTATE_eofbit;
3597 if (ch)
3598 base->state |= IOSTATE_failbit;
3600 if (ch)
3601 *ch = ret;
3602 istream_isfx(this);
3604 return ret;
3607 /* ?get@istream@@QAEAAV1@AAC@Z */
3608 /* ?get@istream@@QEAAAEAV1@AEAC@Z */
3609 /* ?get@istream@@QAEAAV1@AAD@Z */
3610 /* ?get@istream@@QEAAAEAV1@AEAD@Z */
3611 /* ?get@istream@@QAEAAV1@AAE@Z */
3612 /* ?get@istream@@QEAAAEAV1@AEAE@Z */
3613 DEFINE_THISCALL_WRAPPER(istream_get_char, 8)
3614 istream* __thiscall istream_get_char(istream *this, char *ch)
3616 istream_internal_get_char(this, ch);
3617 return this;
3620 /* ?get@istream@@QAEHXZ */
3621 /* ?get@istream@@QEAAHXZ */
3622 DEFINE_THISCALL_WRAPPER(istream_get, 4)
3623 int __thiscall istream_get(istream *this)
3625 return istream_internal_get_char(this, NULL);
3628 /* ?get@istream@@QAEAAV1@AAVstreambuf@@D@Z */
3629 /* ?get@istream@@QEAAAEAV1@AEAVstreambuf@@D@Z */
3630 DEFINE_THISCALL_WRAPPER(istream_get_sb, 12)
3631 istream* __thiscall istream_get_sb(istream *this, streambuf *sb, char delim)
3633 ios *base = istream_get_ios(this);
3634 int ch;
3636 TRACE("(%p %p %c)\n", this, sb, delim);
3638 if (istream_ipfx(this, 1)) {
3639 for (ch = streambuf_sgetc(base->sb); ch != delim; ch = streambuf_snextc(base->sb)) {
3640 if (ch == EOF) {
3641 base->state |= IOSTATE_eofbit;
3642 break;
3644 if (streambuf_sputc(sb, ch) == EOF)
3645 base->state |= IOSTATE_failbit;
3646 this->count++;
3648 istream_isfx(this);
3650 return this;
3653 /* ?getline@istream@@QAEAAV1@PACHD@Z */
3654 /* ?getline@istream@@QEAAAEAV1@PEACHD@Z */
3655 /* ?getline@istream@@QAEAAV1@PADHD@Z */
3656 /* ?getline@istream@@QEAAAEAV1@PEADHD@Z */
3657 /* ?getline@istream@@QAEAAV1@PAEHD@Z */
3658 /* ?getline@istream@@QEAAAEAV1@PEAEHD@Z */
3659 DEFINE_THISCALL_WRAPPER(istream_getline, 16)
3660 istream* __thiscall istream_getline(istream *this, char *str, int count, char delim)
3662 ios *base = istream_get_ios(this);
3664 TRACE("(%p %p %d %c)\n", this, str, count, delim);
3666 ios_lock(base);
3667 this->extract_delim++;
3668 istream_get_str_delim(this, str, count, (unsigned char) delim);
3669 ios_unlock(base);
3670 return this;
3673 /* ?ignore@istream@@QAEAAV1@HH@Z */
3674 /* ?ignore@istream@@QEAAAEAV1@HH@Z */
3675 DEFINE_THISCALL_WRAPPER(istream_ignore, 12)
3676 istream* __thiscall istream_ignore(istream *this, int count, int delim)
3678 ios *base = istream_get_ios(this);
3680 TRACE("(%p %d %d)\n", this, count, delim);
3682 ios_lock(base);
3683 this->extract_delim++;
3684 istream_get_str_delim(this, NULL, count + 1, delim);
3685 ios_unlock(base);
3686 return this;
3689 /* ?peek@istream@@QAEHXZ */
3690 /* ?peek@istream@@QEAAHXZ */
3691 DEFINE_THISCALL_WRAPPER(istream_peek, 4)
3692 int __thiscall istream_peek(istream *this)
3694 ios *base = istream_get_ios(this);
3695 int ret = EOF;
3697 TRACE("(%p)\n", this);
3699 if (istream_ipfx(this, 1)) {
3700 ret = streambuf_sgetc(base->sb);
3701 istream_isfx(this);
3703 return ret;
3706 /* ?putback@istream@@QAEAAV1@D@Z */
3707 /* ?putback@istream@@QEAAAEAV1@D@Z */
3708 DEFINE_THISCALL_WRAPPER(istream_putback, 8)
3709 istream* __thiscall istream_putback(istream *this, char ch)
3711 ios *base = istream_get_ios(this);
3713 TRACE("(%p %c)\n", this, ch);
3715 if (ios_good(base)) {
3716 ios_lockbuf(base);
3717 if (streambuf_sputbackc(base->sb, ch) == EOF)
3718 ios_clear(base, base->state | IOSTATE_failbit);
3719 ios_unlockbuf(base);
3721 return this;
3724 /* ?read@istream@@QAEAAV1@PACH@Z */
3725 /* ?read@istream@@QEAAAEAV1@PEACH@Z */
3726 /* ?read@istream@@QAEAAV1@PADH@Z */
3727 /* ?read@istream@@QEAAAEAV1@PEADH@Z */
3728 /* ?read@istream@@QAEAAV1@PAEH@Z */
3729 /* ?read@istream@@QEAAAEAV1@PEAEH@Z */
3730 DEFINE_THISCALL_WRAPPER(istream_read, 12)
3731 istream* __thiscall istream_read(istream *this, char *str, int count)
3733 ios *base = istream_get_ios(this);
3735 TRACE("(%p %p %d)\n", this, str, count);
3737 if (istream_ipfx(this, 1)) {
3738 if ((this->count = streambuf_sgetn(base->sb, str, count)) != count)
3739 base->state = IOSTATE_eofbit | IOSTATE_failbit;
3740 istream_isfx(this);
3742 return this;
3745 /* ?seekg@istream@@QAEAAV1@J@Z */
3746 /* ?seekg@istream@@QEAAAEAV1@J@Z */
3747 DEFINE_THISCALL_WRAPPER(istream_seekg, 8)
3748 istream* __thiscall istream_seekg(istream *this, streampos pos)
3750 ios *base = istream_get_ios(this);
3752 TRACE("(%p %ld)\n", this, pos);
3754 ios_lockbuf(base);
3755 if (streambuf_seekpos(base->sb, pos, OPENMODE_in) == EOF)
3756 ios_clear(base, base->state | IOSTATE_failbit);
3757 ios_unlockbuf(base);
3758 return this;
3761 /* ?seekg@istream@@QAEAAV1@JW4seek_dir@ios@@@Z */
3762 /* ?seekg@istream@@QEAAAEAV1@JW4seek_dir@ios@@@Z */
3763 DEFINE_THISCALL_WRAPPER(istream_seekg_offset, 12)
3764 istream* __thiscall istream_seekg_offset(istream *this, streamoff off, ios_seek_dir dir)
3766 ios *base = istream_get_ios(this);
3768 TRACE("(%p %ld %d)\n", this, off, dir);
3770 ios_lockbuf(base);
3771 if (call_streambuf_seekoff(base->sb, off, dir, OPENMODE_in) == EOF)
3772 ios_clear(base, base->state | IOSTATE_failbit);
3773 ios_unlockbuf(base);
3774 return this;
3777 /* ?sync@istream@@QAEHXZ */
3778 /* ?sync@istream@@QEAAHXZ */
3779 DEFINE_THISCALL_WRAPPER(istream_sync, 4)
3780 int __thiscall istream_sync(istream *this)
3782 ios *base = istream_get_ios(this);
3783 int ret;
3785 TRACE("(%p)\n", this);
3787 ios_lockbuf(base);
3788 if ((ret = call_streambuf_sync(base->sb)) == EOF)
3789 ios_clear(base, base->state | IOSTATE_badbit | IOSTATE_failbit);
3790 ios_unlockbuf(base);
3791 return ret;
3794 /* ?tellg@istream@@QAEJXZ */
3795 /* ?tellg@istream@@QEAAJXZ */
3796 DEFINE_THISCALL_WRAPPER(istream_tellg, 4)
3797 streampos __thiscall istream_tellg(istream *this)
3799 ios *base = istream_get_ios(this);
3800 streampos pos;
3802 TRACE("(%p)\n", this);
3804 ios_lockbuf(base);
3805 if ((pos = call_streambuf_seekoff(base->sb, 0, SEEKDIR_cur, OPENMODE_in)) == EOF)
3806 ios_clear(base, base->state | IOSTATE_failbit);
3807 ios_unlockbuf(base);
3808 return pos;
3811 static int getint_is_valid_digit(char ch, int base)
3813 if (base == 8) return (ch >= '0' && ch <= '7');
3814 if (base == 16) return isxdigit(ch);
3815 return isdigit(ch);
3818 /* ?getint@istream@@AAEHPAD@Z */
3819 /* ?getint@istream@@AEAAHPEAD@Z */
3820 DEFINE_THISCALL_WRAPPER(istream_getint, 8)
3821 int __thiscall istream_getint(istream *this, char *str)
3823 ios *base = istream_get_ios(this);
3824 int ch, num_base = 0, i = 0;
3825 BOOL scan_sign = TRUE, scan_prefix = TRUE, scan_x = FALSE, valid_integer = FALSE;
3827 TRACE("(%p %p)\n", this, str);
3829 if (istream_ipfx(this, 0)) {
3830 num_base = (base->flags & FLAGS_dec) ? 10 :
3831 (base->flags & FLAGS_hex) ? 16 :
3832 (base->flags & FLAGS_oct) ? 8 : 0; /* 0 = autodetect */
3833 /* scan valid characters, up to 15 (hard limit on Windows) */
3834 for (ch = streambuf_sgetc(base->sb); i < 15; ch = streambuf_snextc(base->sb)) {
3835 if ((ch == '+' || ch == '-') && scan_sign) {
3836 /* no additional sign allowed */
3837 scan_sign = FALSE;
3838 } else if ((ch == 'x' || ch == 'X') && scan_x) {
3839 /* only hex digits can (and must) follow */
3840 scan_x = valid_integer = FALSE;
3841 num_base = 16;
3842 } else if (ch == '0' && scan_prefix) {
3843 /* might be the octal prefix, the beginning of the hex prefix or a decimal zero */
3844 scan_sign = scan_prefix = FALSE;
3845 scan_x = !num_base || num_base == 16;
3846 valid_integer = TRUE;
3847 if (!num_base)
3848 num_base = 8;
3849 } else if (getint_is_valid_digit(ch, num_base)) {
3850 /* only digits in the corresponding base can follow */
3851 scan_sign = scan_prefix = scan_x = FALSE;
3852 valid_integer = TRUE;
3853 } else {
3854 /* unexpected character, stop scanning */
3855 if (!valid_integer) {
3856 /* the result is not a valid integer */
3857 base->state |= IOSTATE_failbit;
3858 /* put any extracted character back into the stream */
3859 while (i > 0)
3860 if (streambuf_sputbackc(base->sb, str[--i]) == EOF)
3861 base->state |= IOSTATE_badbit; /* characters have been lost for good */
3862 } else if (ch == EOF) {
3863 base->state |= IOSTATE_eofbit;
3864 if (scan_x && !(base->flags & ios_basefield)) {
3865 /* when autodetecting, a single zero followed by EOF is regarded as decimal */
3866 num_base = 0;
3869 break;
3871 str[i++] = ch;
3873 /* append a null terminator */
3874 str[i] = 0;
3875 istream_isfx(this);
3877 return num_base;
3880 /* ?getdouble@istream@@AAEHPADH@Z */
3881 /* ?getdouble@istream@@AEAAHPEADH@Z */
3882 DEFINE_THISCALL_WRAPPER(istream_getdouble, 12)
3883 int __thiscall istream_getdouble(istream *this, char *str, int count)
3885 ios *base = istream_get_ios(this);
3886 int ch, i = 0;
3887 BOOL scan_sign = TRUE, scan_dot = TRUE, scan_exp = TRUE,
3888 valid_mantissa = FALSE, valid_exponent = FALSE;
3890 TRACE("(%p %p %d)\n", this, str, count);
3892 if (istream_ipfx(this, 0)) {
3893 if (!count) {
3894 /* can't output anything */
3895 base->state |= IOSTATE_failbit;
3896 i = -1;
3897 } else {
3898 /* valid mantissas: +d. +.d +d.d (where d are sequences of digits and the sign is optional) */
3899 /* valid exponents: e+d E+d (where d are sequences of digits and the sign is optional) */
3900 for (ch = streambuf_sgetc(base->sb); i < count; ch = streambuf_snextc(base->sb)) {
3901 if ((ch == '+' || ch == '-') && scan_sign) {
3902 /* no additional sign allowed */
3903 scan_sign = FALSE;
3904 } else if (ch == '.' && scan_dot) {
3905 /* no sign or additional dot allowed */
3906 scan_sign = scan_dot = FALSE;
3907 } else if ((ch == 'e' || ch == 'E') && scan_exp) {
3908 /* sign is allowed again but not dots or exponents */
3909 scan_sign = TRUE;
3910 scan_dot = scan_exp = FALSE;
3911 } else if (isdigit(ch)) {
3912 if (scan_exp)
3913 valid_mantissa = TRUE;
3914 else
3915 valid_exponent = TRUE;
3916 /* no sign allowed after a digit */
3917 scan_sign = FALSE;
3918 } else {
3919 /* unexpected character, stop scanning */
3920 /* check whether the result is a valid double */
3921 if (!scan_exp && !valid_exponent) {
3922 /* put the last character back into the stream, usually the 'e' or 'E' */
3923 if (streambuf_sputbackc(base->sb, str[i--]) == EOF)
3924 base->state |= IOSTATE_badbit; /* characters have been lost for good */
3925 } else if (ch == EOF)
3926 base->state |= IOSTATE_eofbit;
3927 if (!valid_mantissa)
3928 base->state |= IOSTATE_failbit;
3929 break;
3931 str[i++] = ch;
3933 /* check if character limit has been reached */
3934 if (i == count) {
3935 base->state |= IOSTATE_failbit;
3936 i--;
3938 /* append a null terminator */
3939 str[i] = 0;
3941 istream_isfx(this);
3943 return i;
3946 /* ??5istream@@QAEAAV0@AAC@Z */
3947 /* ??5istream@@QEAAAEAV0@AEAC@Z */
3948 /* ??5istream@@QAEAAV0@AAD@Z */
3949 /* ??5istream@@QEAAAEAV0@AEAD@Z */
3950 /* ??5istream@@QAEAAV0@AAE@Z */
3951 /* ??5istream@@QEAAAEAV0@AEAE@Z */
3952 DEFINE_THISCALL_WRAPPER(istream_read_char, 8)
3953 istream* __thiscall istream_read_char(istream *this, char *ch)
3955 ios *base = istream_get_ios(this);
3956 int ret;
3958 TRACE("(%p %p)\n", this, ch);
3960 if (istream_ipfx(this, 0)) {
3961 if ((ret = streambuf_sbumpc(base->sb)) == EOF)
3962 base->state |= IOSTATE_eofbit | IOSTATE_failbit;
3963 else
3964 *ch = ret;
3965 istream_isfx(this);
3967 return this;
3970 /* ??5istream@@QAEAAV0@PAC@Z */
3971 /* ??5istream@@QEAAAEAV0@PEAC@Z */
3972 /* ??5istream@@QAEAAV0@PAD@Z */
3973 /* ??5istream@@QEAAAEAV0@PEAD@Z */
3974 /* ??5istream@@QAEAAV0@PAE@Z */
3975 /* ??5istream@@QEAAAEAV0@PEAE@Z */
3976 DEFINE_THISCALL_WRAPPER(istream_read_str, 8)
3977 istream* __thiscall istream_read_str(istream *this, char *str)
3979 ios *base = istream_get_ios(this);
3980 int ch, count = 0;
3982 TRACE("(%p %p)\n", this, str);
3984 if (istream_ipfx(this, 0)) {
3985 if (str) {
3986 for (ch = streambuf_sgetc(base->sb);
3987 count < (unsigned int) base->width - 1 && !isspace(ch);
3988 ch = streambuf_snextc(base->sb)) {
3989 if (ch == EOF) {
3990 base->state |= IOSTATE_eofbit;
3991 break;
3993 str[count++] = ch;
3996 if (!count) /* nothing to output */
3997 base->state |= IOSTATE_failbit;
3998 else /* append a null terminator */
3999 str[count] = 0;
4000 base->width = 0;
4001 istream_isfx(this);
4003 return this;
4006 static LONG istream_internal_read_integer(istream *this, LONG min_value, LONG max_value, BOOL set_flag)
4008 ios *base = istream_get_ios(this);
4009 char buffer[16];
4010 int num_base;
4011 LONG ret;
4013 TRACE("(%p %ld %ld %d)\n", this, min_value, max_value, set_flag);
4015 num_base = istream_getint(this, buffer);
4016 errno = 0;
4017 ret = strtol(buffer, NULL, num_base);
4018 /* check for overflow and whether the value fits in the output var */
4019 if (set_flag && errno == ERANGE) {
4020 base->state |= IOSTATE_failbit;
4021 } else if (ret > max_value) {
4022 base->state |= IOSTATE_failbit;
4023 ret = max_value;
4024 } else if (ret < min_value) {
4025 base->state |= IOSTATE_failbit;
4026 ret = min_value;
4028 return ret;
4031 static ULONG istream_internal_read_unsigned_integer(istream *this, LONG min_value, ULONG max_value)
4033 ios *base = istream_get_ios(this);
4034 char buffer[16];
4035 int num_base;
4036 ULONG ret;
4038 TRACE("(%p %ld %lu)\n", this, min_value, max_value);
4040 num_base = istream_getint(this, buffer);
4041 errno = 0;
4042 ret = strtoul(buffer, NULL, num_base);
4043 /* check for overflow and whether the value fits in the output var */
4044 if ((ret == ULONG_MAX && errno == ERANGE) ||
4045 (ret > max_value && ret < (ULONG) min_value)) {
4046 base->state |= IOSTATE_failbit;
4047 ret = max_value;
4049 return ret;
4052 /* ??5istream@@QAEAAV0@AAF@Z */
4053 /* ??5istream@@QEAAAEAV0@AEAF@Z */
4054 DEFINE_THISCALL_WRAPPER(istream_read_short, 8)
4055 istream* __thiscall istream_read_short(istream *this, short *p)
4057 if (istream_ipfx(this, 0)) {
4058 *p = istream_internal_read_integer(this, SHRT_MIN, SHRT_MAX, FALSE);
4059 istream_isfx(this);
4061 return this;
4064 /* ??5istream@@QAEAAV0@AAG@Z */
4065 /* ??5istream@@QEAAAEAV0@AEAG@Z */
4066 DEFINE_THISCALL_WRAPPER(istream_read_unsigned_short, 8)
4067 istream* __thiscall istream_read_unsigned_short(istream *this, unsigned short *p)
4069 if (istream_ipfx(this, 0)) {
4070 *p = istream_internal_read_unsigned_integer(this, SHRT_MIN, USHRT_MAX);
4071 istream_isfx(this);
4073 return this;
4076 /* ??5istream@@QAEAAV0@AAH@Z */
4077 /* ??5istream@@QEAAAEAV0@AEAH@Z */
4078 DEFINE_THISCALL_WRAPPER(istream_read_int, 8)
4079 istream* __thiscall istream_read_int(istream *this, int *p)
4081 if (istream_ipfx(this, 0)) {
4082 *p = istream_internal_read_integer(this, INT_MIN, INT_MAX, FALSE);
4083 istream_isfx(this);
4085 return this;
4088 /* ??5istream@@QAEAAV0@AAI@Z */
4089 /* ??5istream@@QEAAAEAV0@AEAI@Z */
4090 DEFINE_THISCALL_WRAPPER(istream_read_unsigned_int, 8)
4091 istream* __thiscall istream_read_unsigned_int(istream *this, unsigned int *p)
4093 if (istream_ipfx(this, 0)) {
4094 *p = istream_internal_read_unsigned_integer(this, INT_MIN, UINT_MAX);
4095 istream_isfx(this);
4097 return this;
4100 /* ??5istream@@QAEAAV0@AAJ@Z */
4101 /* ??5istream@@QEAAAEAV0@AEAJ@Z */
4102 DEFINE_THISCALL_WRAPPER(istream_read_long, 8)
4103 istream* __thiscall istream_read_long(istream *this, LONG *p)
4105 if (istream_ipfx(this, 0)) {
4106 *p = istream_internal_read_integer(this, LONG_MIN, LONG_MAX, TRUE);
4107 istream_isfx(this);
4109 return this;
4112 /* ??5istream@@QAEAAV0@AAK@Z */
4113 /* ??5istream@@QEAAAEAV0@AEAK@Z */
4114 DEFINE_THISCALL_WRAPPER(istream_read_unsigned_long, 8)
4115 istream* __thiscall istream_read_unsigned_long(istream *this, ULONG *p)
4117 if (istream_ipfx(this, 0)) {
4118 *p = istream_internal_read_unsigned_integer(this, LONG_MIN, ULONG_MAX);
4119 istream_isfx(this);
4121 return this;
4124 static BOOL istream_internal_read_float(istream *this, int max_chars, double *out)
4126 char buffer[32];
4127 BOOL read = FALSE;
4129 TRACE("(%p %d %p)\n", this, max_chars, out);
4131 if (istream_ipfx(this, 0)) {
4132 /* character count is limited on Windows */
4133 if (istream_getdouble(this, buffer, max_chars) > 0) {
4134 *out = strtod(buffer, NULL);
4135 read = TRUE;
4137 istream_isfx(this);
4139 return read;
4142 /* ??5istream@@QAEAAV0@AAM@Z */
4143 /* ??5istream@@QEAAAEAV0@AEAM@Z */
4144 DEFINE_THISCALL_WRAPPER(istream_read_float, 8)
4145 istream* __thiscall istream_read_float(istream *this, float *f)
4147 double tmp;
4148 if (istream_internal_read_float(this, 20, &tmp)) {
4149 /* check whether the value fits in the output var */
4150 if (tmp > FLT_MAX)
4151 tmp = FLT_MAX;
4152 else if (tmp < -FLT_MAX)
4153 tmp = -FLT_MAX;
4154 else if (tmp > 0 && tmp < FLT_MIN)
4155 tmp = FLT_MIN;
4156 else if (tmp < 0 && tmp > -FLT_MIN)
4157 tmp = -FLT_MIN;
4158 *f = tmp;
4160 return this;
4163 /* ??5istream@@QAEAAV0@AAN@Z */
4164 /* ??5istream@@QEAAAEAV0@AEAN@Z */
4165 DEFINE_THISCALL_WRAPPER(istream_read_double, 8)
4166 istream* __thiscall istream_read_double(istream *this, double *d)
4168 istream_internal_read_float(this, 28, d);
4169 return this;
4172 /* ??5istream@@QAEAAV0@AAO@Z */
4173 /* ??5istream@@QEAAAEAV0@AEAO@Z */
4174 DEFINE_THISCALL_WRAPPER(istream_read_long_double, 8)
4175 istream* __thiscall istream_read_long_double(istream *this, double *ld)
4177 istream_internal_read_float(this, 32, ld);
4178 return this;
4181 /* ??5istream@@QAEAAV0@PAVstreambuf@@@Z */
4182 /* ??5istream@@QEAAAEAV0@PEAVstreambuf@@@Z */
4183 DEFINE_THISCALL_WRAPPER(istream_read_streambuf, 8)
4184 istream* __thiscall istream_read_streambuf(istream *this, streambuf *sb)
4186 ios *base = istream_get_ios(this);
4187 int ch;
4189 TRACE("(%p %p)\n", this, sb);
4191 if (istream_ipfx(this, 0)) {
4192 while ((ch = streambuf_sbumpc(base->sb)) != EOF)
4193 if (streambuf_sputc(sb, ch) == EOF)
4194 base->state |= IOSTATE_failbit;
4195 istream_isfx(this);
4197 return this;
4200 /* ??5istream@@QAEAAV0@P6AAAV0@AAV0@@Z@Z */
4201 /* ??5istream@@QEAAAEAV0@P6AAEAV0@AEAV0@@Z@Z */
4202 DEFINE_THISCALL_WRAPPER(istream_read_manip, 8)
4203 istream* __thiscall istream_read_manip(istream *this, istream* (__cdecl *func)(istream*))
4205 TRACE("(%p %p)\n", this, func);
4206 return func(this);
4209 /* ??5istream@@QAEAAV0@P6AAAVios@@AAV1@@Z@Z */
4210 /* ??5istream@@QEAAAEAV0@P6AAEAVios@@AEAV1@@Z@Z */
4211 DEFINE_THISCALL_WRAPPER(istream_read_ios_manip, 8)
4212 istream* __thiscall istream_read_ios_manip(istream *this, ios* (__cdecl *func)(ios*))
4214 TRACE("(%p %p)\n", this, func);
4215 func(istream_get_ios(this));
4216 return this;
4219 /* ?ws@@YAAAVistream@@AAV1@@Z */
4220 /* ?ws@@YAAEAVistream@@AEAV1@@Z */
4221 istream* __cdecl istream_ws(istream *this)
4223 TRACE("(%p)\n", this);
4224 istream_eatwhite(this);
4225 return this;
4228 /* ??0istream_withassign@@QAE@ABV0@@Z */
4229 /* ??0istream_withassign@@QEAA@AEBV0@@Z */
4230 DEFINE_THISCALL_WRAPPER(istream_withassign_copy_ctor, 12)
4231 istream* __thiscall istream_withassign_copy_ctor(istream *this, const istream *copy, BOOL virt_init)
4233 ios *base, *base_copy;
4235 TRACE("(%p %p %d)\n", this, copy, virt_init);
4237 base_copy = istream_get_ios(copy);
4238 if (virt_init) {
4239 this->vbtable = istream_vbtable;
4240 base = istream_get_ios(this);
4241 ios_copy_ctor(base, base_copy);
4242 } else
4243 base = istream_get_ios(this);
4244 ios_init(base, base_copy->sb);
4245 base->vtable = &istream_withassign_vtable;
4246 base->flags |= FLAGS_skipws;
4247 this->extract_delim = 0;
4248 this->count = 0;
4249 return this;
4252 /* ??0istream_withassign@@QAE@PAVstreambuf@@@Z */
4253 /* ??0istream_withassign@@QEAA@PEAVstreambuf@@@Z */
4254 DEFINE_THISCALL_WRAPPER(istream_withassign_sb_ctor, 12)
4255 istream* __thiscall istream_withassign_sb_ctor(istream *this, streambuf *sb, BOOL virt_init)
4257 ios *base;
4259 TRACE("(%p %p %d)\n", this, sb, virt_init);
4261 istream_sb_ctor(this, sb, virt_init);
4262 base = istream_get_ios(this);
4263 base->vtable = &istream_withassign_vtable;
4264 return this;
4267 /* ??0istream_withassign@@QAE@XZ */
4268 /* ??0istream_withassign@@QEAA@XZ */
4269 DEFINE_THISCALL_WRAPPER(istream_withassign_ctor, 8)
4270 istream* __thiscall istream_withassign_ctor(istream *this, BOOL virt_init)
4272 ios *base;
4274 TRACE("(%p %d)\n", this, virt_init);
4276 istream_ctor(this, virt_init);
4277 base = istream_get_ios(this);
4278 base->vtable = &istream_withassign_vtable;
4279 return this;
4282 /* ??0istrstream@@QAE@ABV0@@Z */
4283 /* ??0istrstream@@QEAA@AEBV0@@Z */
4284 DEFINE_THISCALL_WRAPPER(istrstream_copy_ctor, 12)
4285 istream* __thiscall istrstream_copy_ctor(istream *this, const istream *copy, BOOL virt_init)
4287 TRACE("(%p %p %d)\n", this, copy, virt_init);
4288 istream_withassign_copy_ctor(this, copy, virt_init);
4289 istream_get_ios(this)->vtable = &istrstream_vtable;
4290 return this;
4293 /* ??0istrstream@@QAE@PADH@Z */
4294 /* ??0istrstream@@QEAA@PEADH@Z */
4295 DEFINE_THISCALL_WRAPPER(istrstream_buffer_ctor, 16)
4296 istream* __thiscall istrstream_buffer_ctor(istream *this, char *buffer, int length, BOOL virt_init)
4298 ios *base;
4299 strstreambuf *ssb = operator_new(sizeof(strstreambuf));
4301 TRACE("(%p %p %d %d)\n", this, buffer, length, virt_init);
4303 if (!ssb) {
4304 FIXME("out of memory\n");
4305 return NULL;
4308 strstreambuf_buffer_ctor(ssb, buffer, length, NULL);
4309 istream_sb_ctor(this, &ssb->base, virt_init);
4311 base = istream_get_ios(this);
4312 base->vtable = &istrstream_vtable;
4313 base->delbuf = 1;
4314 return this;
4317 /* ??0istrstream@@QAE@PAD@Z */
4318 /* ??0istrstream@@QEAA@PEAD@Z */
4319 DEFINE_THISCALL_WRAPPER(istrstream_str_ctor, 12)
4320 istream* __thiscall istrstream_str_ctor(istream *this, char *str, BOOL virt_init)
4322 return istrstream_buffer_ctor(this, str, 0, virt_init);
4325 /* ?rdbuf@istrstream@@QBEPAVstrstreambuf@@XZ */
4326 /* ?rdbuf@istrstream@@QEBAPEAVstrstreambuf@@XZ */
4327 DEFINE_THISCALL_WRAPPER(istrstream_rdbuf, 4)
4328 strstreambuf* __thiscall istrstream_rdbuf(const istream *this)
4330 return (strstreambuf*) istream_get_ios(this)->sb;
4333 /* ?str@istrstream@@QAEPADXZ */
4334 /* ?str@istrstream@@QEAAPEADXZ */
4335 DEFINE_THISCALL_WRAPPER(istrstream_str, 4)
4336 char* __thiscall istrstream_str(istream *this)
4338 return strstreambuf_str(istrstream_rdbuf(this));
4341 /* ??0ifstream@@QAE@ABV0@@Z */
4342 /* ??0ifstream@@QEAA@AEBV0@@Z */
4343 DEFINE_THISCALL_WRAPPER(ifstream_copy_ctor, 12)
4344 istream* __thiscall ifstream_copy_ctor(istream *this, const istream *copy, BOOL virt_init)
4346 TRACE("(%p %p %d)\n", this, copy, virt_init);
4347 istream_withassign_copy_ctor(this, copy, virt_init);
4348 istream_get_ios(this)->vtable = &ifstream_vtable;
4349 return this;
4352 /* ??0ifstream@@QAE@HPADH@Z */
4353 /* ??0ifstream@@QEAA@HPEADH@Z */
4354 DEFINE_THISCALL_WRAPPER(ifstream_buffer_ctor, 20)
4355 istream* __thiscall ifstream_buffer_ctor(istream *this, filedesc fd, char *buffer, int length, BOOL virt_init)
4357 ios *base;
4358 filebuf *fb = operator_new(sizeof(filebuf));
4360 TRACE("(%p %d %p %d %d)\n", this, fd, buffer, length, virt_init);
4362 if (!fb) {
4363 FIXME("out of memory\n");
4364 return NULL;
4367 filebuf_fd_reserve_ctor(fb, fd, buffer, length);
4368 istream_sb_ctor(this, &fb->base, virt_init);
4370 base = istream_get_ios(this);
4371 base->vtable = &ifstream_vtable;
4372 base->delbuf = 1;
4374 return this;
4377 /* ??0ifstream@@QAE@H@Z */
4378 /* ??0ifstream@@QEAA@H@Z */
4379 DEFINE_THISCALL_WRAPPER(ifstream_fd_ctor, 12)
4380 istream* __thiscall ifstream_fd_ctor(istream *this, filedesc fd, BOOL virt_init)
4382 ios *base;
4383 filebuf *fb = operator_new(sizeof(filebuf));
4385 TRACE("(%p %d %d)\n", this, fd, virt_init);
4387 if (!fb) {
4388 FIXME("out of memory\n");
4389 return NULL;
4392 filebuf_fd_ctor(fb, fd);
4393 istream_sb_ctor(this, &fb->base, virt_init);
4395 base = istream_get_ios(this);
4396 base->vtable = &ifstream_vtable;
4397 base->delbuf = 1;
4399 return this;
4402 /* ??0ifstream@@QAE@PBDHH@Z */
4403 /* ??0ifstream@@QEAA@PEBDHH@Z */
4404 DEFINE_THISCALL_WRAPPER(ifstream_open_ctor, 20)
4405 istream* __thiscall ifstream_open_ctor(istream *this, const char *name, ios_open_mode mode, int protection, BOOL virt_init)
4407 ios *base;
4408 filebuf *fb = operator_new(sizeof(filebuf));
4410 TRACE("(%p %s %d %d %d)\n", this, name, mode, protection, virt_init);
4412 if (!fb) {
4413 FIXME("out of memory\n");
4414 return NULL;
4417 filebuf_ctor(fb);
4418 istream_sb_ctor(this, &fb->base, virt_init);
4420 base = istream_get_ios(this);
4421 base->vtable = &ifstream_vtable;
4422 base->delbuf = 1;
4424 if (filebuf_open(fb, name, mode|OPENMODE_in, protection) == NULL)
4425 base->state |= IOSTATE_failbit;
4426 return this;
4429 /* ??0ifstream@@QAE@XZ */
4430 /* ??0ifstream@@QEAA@XZ */
4431 DEFINE_THISCALL_WRAPPER(ifstream_ctor, 8)
4432 istream* __thiscall ifstream_ctor(istream *this, BOOL virt_init)
4434 return ifstream_fd_ctor(this, -1, virt_init);
4437 /* ?rdbuf@ifstream@@QBEPAVfilebuf@@XZ */
4438 /* ?rdbuf@ifstream@@QEBAPEAVfilebuf@@XZ */
4439 DEFINE_THISCALL_WRAPPER(ifstream_rdbuf, 4)
4440 filebuf* __thiscall ifstream_rdbuf(const istream *this)
4442 TRACE("(%p)\n", this);
4443 return (filebuf*) istream_get_ios(this)->sb;
4446 /* ?fd@ifstream@@QBEHXZ */
4447 /* ?fd@ifstream@@QEBAHXZ */
4448 DEFINE_THISCALL_WRAPPER(ifstream_fd, 4)
4449 filedesc __thiscall ifstream_fd(istream *this)
4451 TRACE("(%p)\n", this);
4452 return filebuf_fd(ifstream_rdbuf(this));
4455 /* ?attach@ifstream@@QAEXH@Z */
4456 /* ?attach@ifstream@@QEAAXH@Z */
4457 DEFINE_THISCALL_WRAPPER(ifstream_attach, 8)
4458 void __thiscall ifstream_attach(istream *this, filedesc fd)
4460 ios *base = istream_get_ios(this);
4461 TRACE("(%p %d)\n", this, fd);
4462 if (filebuf_attach(ifstream_rdbuf(this), fd) == NULL)
4463 ios_clear(base, base->state | IOSTATE_failbit);
4466 /* ?close@ifstream@@QAEXXZ */
4467 /* ?close@ifstream@@QEAAXXZ */
4468 DEFINE_THISCALL_WRAPPER(ifstream_close, 4)
4469 void __thiscall ifstream_close(istream *this)
4471 ios *base = istream_get_ios(this);
4472 TRACE("(%p)\n", this);
4473 if (filebuf_close(ifstream_rdbuf(this)) == NULL)
4474 ios_clear(base, base->state | IOSTATE_failbit);
4475 else
4476 ios_clear(base, IOSTATE_goodbit);
4479 /* ?is_open@ifstream@@QBEHXZ */
4480 /* ?is_open@ifstream@@QEBAHXZ */
4481 DEFINE_THISCALL_WRAPPER(ifstream_is_open, 4)
4482 int __thiscall ifstream_is_open(const istream *this)
4484 TRACE("(%p)\n", this);
4485 return filebuf_is_open(ifstream_rdbuf(this));
4488 /* ?open@ifstream@@QAEXPBDHH@Z */
4489 /* ?open@ifstream@@QEAAXPEBDHH@Z */
4490 DEFINE_THISCALL_WRAPPER(ifstream_open, 16)
4491 void __thiscall ifstream_open(istream *this, const char *name, ios_open_mode mode, int protection)
4493 ios *base = istream_get_ios(this);
4494 TRACE("(%p %s %d %d)\n", this, name, mode, protection);
4495 if (filebuf_open(ifstream_rdbuf(this), name, mode|OPENMODE_in, protection) == NULL)
4496 ios_clear(base, base->state | IOSTATE_failbit);
4499 /* ?setbuf@ifstream@@QAEPAVstreambuf@@PADH@Z */
4500 /* ?setbuf@ifstream@@QEAAPEAVstreambuf@@PEADH@Z */
4501 DEFINE_THISCALL_WRAPPER(ifstream_setbuf, 12)
4502 streambuf* __thiscall ifstream_setbuf(istream *this, char *buffer, int length)
4504 ios *base = istream_get_ios(this);
4505 filebuf* fb = ifstream_rdbuf(this);
4507 TRACE("(%p %p %d)\n", this, buffer, length);
4509 if (filebuf_is_open(fb)) {
4510 ios_clear(base, base->state | IOSTATE_failbit);
4511 return NULL;
4514 return filebuf_setbuf(fb, buffer, length);
4517 /* ?setmode@ifstream@@QAEHH@Z */
4518 /* ?setmode@ifstream@@QEAAHH@Z */
4519 DEFINE_THISCALL_WRAPPER(ifstream_setmode, 8)
4520 int __thiscall ifstream_setmode(istream *this, int mode)
4522 TRACE("(%p %d)\n", this, mode);
4523 return filebuf_setmode(ifstream_rdbuf(this), mode);
4526 static inline ios* iostream_to_ios(const iostream *this)
4528 return (ios*)((char*)this + iostream_vbtable_istream[1]);
4531 static inline iostream* ios_to_iostream(const ios *base)
4533 return (iostream*)((char*)base - iostream_vbtable_istream[1]);
4536 /* ??0iostream@@IAE@XZ */
4537 /* ??0iostream@@IEAA@XZ */
4538 DEFINE_THISCALL_WRAPPER(iostream_ctor, 8)
4539 iostream* __thiscall iostream_ctor(iostream *this, BOOL virt_init)
4541 ios *base;
4543 TRACE("(%p %d)\n", this, virt_init);
4545 if (virt_init) {
4546 this->base1.vbtable = iostream_vbtable_istream;
4547 this->base2.vbtable = iostream_vbtable_ostream;
4548 base = istream_get_ios(&this->base1);
4549 ios_ctor(base);
4550 } else
4551 base = istream_get_ios(&this->base1);
4552 istream_ctor(&this->base1, FALSE);
4553 ostream_ctor(&this->base2, FALSE);
4554 base->vtable = &iostream_vtable;
4555 return this;
4558 /* ??0iostream@@QAE@PAVstreambuf@@@Z */
4559 /* ??0iostream@@QEAA@PEAVstreambuf@@@Z */
4560 DEFINE_THISCALL_WRAPPER(iostream_sb_ctor, 12)
4561 iostream* __thiscall iostream_sb_ctor(iostream *this, streambuf *sb, BOOL virt_init)
4563 TRACE("(%p %p %d)\n", this, sb, virt_init);
4564 iostream_ctor(this, virt_init);
4565 ios_init(istream_get_ios(&this->base1), sb);
4566 return this;
4569 /* ??0iostream@@IAE@ABV0@@Z */
4570 /* ??0iostream@@IEAA@AEBV0@@Z */
4571 DEFINE_THISCALL_WRAPPER(iostream_copy_ctor, 12)
4572 iostream* __thiscall iostream_copy_ctor(iostream *this, const iostream *copy, BOOL virt_init)
4574 return iostream_sb_ctor(this, istream_get_ios(&copy->base1)->sb, virt_init);
4577 /* ??1iostream@@UAE@XZ */
4578 /* ??1iostream@@UEAA@XZ */
4579 /* ??1stdiostream@@UAE@XZ */
4580 /* ??1stdiostream@@UEAA@XZ */
4581 /* ??1strstream@@UAE@XZ */
4582 /* ??1strstream@@UEAA@XZ */
4583 /* ??1fstream@@UAE@XZ */
4584 /* ??1fstream@@UEAA@XZ */
4585 DEFINE_THISCALL_WRAPPER(iostream_dtor, 4)
4586 void __thiscall iostream_dtor(ios *base)
4588 iostream *this = ios_to_iostream(base);
4590 TRACE("(%p)\n", this);
4592 ostream_dtor(ostream_to_ios(&this->base2));
4593 istream_dtor(istream_to_ios(&this->base1));
4596 /* ??4iostream@@IAEAAV0@PAVstreambuf@@@Z */
4597 /* ??4iostream@@IEAAAEAV0@PEAVstreambuf@@@Z */
4598 DEFINE_THISCALL_WRAPPER(iostream_assign_sb, 8)
4599 iostream* __thiscall iostream_assign_sb(iostream *this, streambuf *sb)
4601 TRACE("(%p %p)\n", this, sb);
4602 this->base1.count = 0;
4603 ostream_assign_sb(&this->base2, sb);
4604 return this;
4607 /* ??4iostream@@IAEAAV0@AAV0@@Z */
4608 /* ??4iostream@@IEAAAEAV0@AEAV0@@Z */
4609 /* ??4stdiostream@@QAEAAV0@AAV0@@Z */
4610 /* ??4stdiostream@@QEAAAEAV0@AEAV0@@Z */
4611 /* ??4strstream@@QAEAAV0@ABV0@@Z */
4612 /* ??4strstream@@QEAAAEAV0@AEBV0@@Z */
4613 DEFINE_THISCALL_WRAPPER(iostream_assign, 8)
4614 iostream* __thiscall iostream_assign(iostream *this, const iostream *rhs)
4616 return iostream_assign_sb(this, istream_get_ios(&rhs->base1)->sb);
4619 /* ??_Diostream@@QAEXXZ */
4620 /* ??_Diostream@@QEAAXXZ */
4621 /* ??_Dstdiostream@@QAEXXZ */
4622 /* ??_Dstdiostream@@QEAAXXZ */
4623 /* ??_Dstrstream@@QAEXXZ */
4624 /* ??_Dstrstream@@QEAAXXZ */
4625 DEFINE_THISCALL_WRAPPER(iostream_vbase_dtor, 4)
4626 void __thiscall iostream_vbase_dtor(iostream *this)
4628 ios *base = iostream_to_ios(this);
4630 TRACE("(%p)\n", this);
4632 iostream_dtor(base);
4633 ios_dtor(base);
4636 /* ??_Eiostream@@UAEPAXI@Z */
4637 /* ??_Estdiostream@@UAEPAXI@Z */
4638 /* ??_Estrstream@@UAEPAXI@Z */
4639 DEFINE_THISCALL_WRAPPER(iostream_vector_dtor, 8)
4640 iostream* __thiscall iostream_vector_dtor(ios *base, unsigned int flags)
4642 iostream *this = ios_to_iostream(base);
4644 TRACE("(%p %x)\n", this, flags);
4646 if (flags & 2) {
4647 /* we have an array, with the number of elements stored before the first object */
4648 INT_PTR i, *ptr = (INT_PTR *)this-1;
4650 for (i = *ptr-1; i >= 0; i--)
4651 iostream_vbase_dtor(this+i);
4652 operator_delete(ptr);
4653 } else {
4654 iostream_vbase_dtor(this);
4655 if (flags & 1)
4656 operator_delete(this);
4658 return this;
4661 /* ??_Giostream@@UAEPAXI@Z */
4662 /* ??_Gstdiostream@@UAEPAXI@Z */
4663 /* ??_Gstrstream@@UAEPAXI@Z */
4664 DEFINE_THISCALL_WRAPPER(iostream_scalar_dtor, 8)
4665 iostream* __thiscall iostream_scalar_dtor(ios *base, unsigned int flags)
4667 iostream *this = ios_to_iostream(base);
4669 TRACE("(%p %x)\n", this, flags);
4671 iostream_vbase_dtor(this);
4672 if (flags & 1) operator_delete(this);
4673 return this;
4676 static iostream* iostream_internal_copy_ctor(iostream *this, const iostream *copy, const vtable_ptr *vtbl, BOOL virt_init)
4678 ios *base, *base_copy = istream_get_ios(&copy->base1);
4680 if (virt_init) {
4681 this->base1.vbtable = iostream_vbtable_istream;
4682 this->base2.vbtable = iostream_vbtable_ostream;
4683 base = istream_get_ios(&this->base1);
4684 ios_copy_ctor(base, base_copy);
4685 } else
4686 base = istream_get_ios(&this->base1);
4687 ios_init(base, base_copy->sb);
4688 istream_ctor(&this->base1, FALSE);
4689 ostream_ctor(&this->base2, FALSE);
4690 base->vtable = vtbl;
4691 return this;
4694 static iostream* iostream_internal_sb_ctor(iostream *this, streambuf *sb, const vtable_ptr *vtbl, BOOL virt_init)
4696 ios *base;
4698 iostream_ctor(this, virt_init);
4699 base = istream_get_ios(&this->base1);
4700 if (sb)
4701 ios_init(base, sb);
4702 base->vtable = vtbl;
4703 base->delbuf = 1;
4704 return this;
4707 /* ??0strstream@@QAE@ABV0@@Z */
4708 /* ??0strstream@@QEAA@AEBV0@@Z */
4709 DEFINE_THISCALL_WRAPPER(strstream_copy_ctor, 12)
4710 iostream* __thiscall strstream_copy_ctor(iostream *this, const iostream *copy, BOOL virt_init)
4712 TRACE("(%p %p %d)\n", this, copy, virt_init);
4713 return iostream_internal_copy_ctor(this, copy, &strstream_vtable, virt_init);
4716 /* ??0strstream@@QAE@PADHH@Z */
4717 /* ??0strstream@@QEAA@PEADHH@Z */
4718 DEFINE_THISCALL_WRAPPER(strstream_buffer_ctor, 20)
4719 iostream* __thiscall strstream_buffer_ctor(iostream *this, char *buffer, int length, int mode, BOOL virt_init)
4721 strstreambuf *ssb = operator_new(sizeof(strstreambuf));
4723 TRACE("(%p %p %d %d %d)\n", this, buffer, length, mode, virt_init);
4725 if (!ssb) {
4726 FIXME("out of memory\n");
4727 return NULL;
4730 strstreambuf_buffer_ctor(ssb, buffer, length, buffer);
4732 if ((mode & OPENMODE_out) && (mode & (OPENMODE_app|OPENMODE_ate)))
4733 ssb->base.pptr = buffer + strlen(buffer);
4735 return iostream_internal_sb_ctor(this, &ssb->base, &strstream_vtable, virt_init);
4738 /* ??0strstream@@QAE@XZ */
4739 /* ??0strstream@@QEAA@XZ */
4740 DEFINE_THISCALL_WRAPPER(strstream_ctor, 8)
4741 iostream* __thiscall strstream_ctor(iostream *this, BOOL virt_init)
4743 strstreambuf *ssb = operator_new(sizeof(strstreambuf));
4745 TRACE("(%p %d)\n", this, virt_init);
4747 if (!ssb) {
4748 FIXME("out of memory\n");
4749 return NULL;
4752 strstreambuf_ctor(ssb);
4754 return iostream_internal_sb_ctor(this, &ssb->base, &strstream_vtable, virt_init);
4757 /* ?pcount@strstream@@QBEHXZ */
4758 /* ?pcount@strstream@@QEBAHXZ */
4759 DEFINE_THISCALL_WRAPPER(strstream_pcount, 4)
4760 int __thiscall strstream_pcount(const iostream *this)
4762 return streambuf_out_waiting(istream_get_ios(&this->base1)->sb);
4765 /* ?rdbuf@strstream@@QBEPAVstrstreambuf@@XZ */
4766 /* ?rdbuf@strstream@@QEBAPEAVstrstreambuf@@XZ */
4767 DEFINE_THISCALL_WRAPPER(strstream_rdbuf, 4)
4768 strstreambuf* __thiscall strstream_rdbuf(const iostream *this)
4770 return (strstreambuf*) istream_get_ios(&this->base1)->sb;
4773 /* ?str@strstream@@QAEPADXZ */
4774 /* ?str@strstream@@QEAAPEADXZ */
4775 DEFINE_THISCALL_WRAPPER(strstream_str, 4)
4776 char* __thiscall strstream_str(iostream *this)
4778 return strstreambuf_str(strstream_rdbuf(this));
4781 /* ??0stdiostream@@QAE@ABV0@@Z */
4782 /* ??0stdiostream@@QEAA@AEBV0@@Z */
4783 DEFINE_THISCALL_WRAPPER(stdiostream_copy_ctor, 12)
4784 iostream* __thiscall stdiostream_copy_ctor(iostream *this, const iostream *copy, BOOL virt_init)
4786 TRACE("(%p %p %d)\n", this, copy, virt_init);
4787 return iostream_internal_copy_ctor(this, copy, &stdiostream_vtable, virt_init);
4790 /* ??0stdiostream@@QAE@PAU_iobuf@@@Z */
4791 /* ??0stdiostream@@QEAA@PEAU_iobuf@@@Z */
4792 DEFINE_THISCALL_WRAPPER(stdiostream_file_ctor, 12)
4793 iostream* __thiscall stdiostream_file_ctor(iostream *this, FILE *file, BOOL virt_init)
4795 stdiobuf *stb = operator_new(sizeof(stdiobuf));
4797 TRACE("(%p %p %d)\n", this, file, virt_init);
4799 if (!stb) {
4800 FIXME("out of memory\n");
4801 return NULL;
4804 stdiobuf_file_ctor(stb, file);
4806 return iostream_internal_sb_ctor(this, &stb->base, &stdiostream_vtable, virt_init);
4809 /* ?rdbuf@stdiostream@@QBEPAVstdiobuf@@XZ */
4810 /* ?rdbuf@stdiostream@@QEBAPEAVstdiobuf@@XZ */
4811 DEFINE_THISCALL_WRAPPER(stdiostream_rdbuf, 4)
4812 stdiobuf* __thiscall stdiostream_rdbuf(const iostream *this)
4814 return (stdiobuf*) istream_get_ios(&this->base1)->sb;
4817 /* ??0fstream@@QAE@ABV0@@Z */
4818 /* ??0fstream@@QEAA@AEBV0@@Z */
4819 DEFINE_THISCALL_WRAPPER(fstream_copy_ctor, 12)
4820 iostream* __thiscall fstream_copy_ctor(iostream *this, const iostream *copy, BOOL virt_init)
4822 TRACE("(%p %p %d)\n", this, copy, virt_init);
4823 iostream_internal_copy_ctor(this, copy, &fstream_vtable, virt_init);
4824 return this;
4827 /* ??0fstream@@QAE@HPADH@Z */
4828 /* ??0fstream@@QEAA@HPEADH@Z */
4829 DEFINE_THISCALL_WRAPPER(fstream_buffer_ctor, 20)
4830 iostream* __thiscall fstream_buffer_ctor(iostream *this, filedesc fd, char *buffer, int length, BOOL virt_init)
4832 ios *base;
4833 filebuf *fb = operator_new(sizeof(filebuf));
4835 TRACE("(%p %d %p %d %d)\n", this, fd, buffer, length, virt_init);
4837 if (!fb) {
4838 FIXME("out of memory\n");
4839 return NULL;
4842 filebuf_fd_reserve_ctor(fb, fd, buffer, length);
4844 iostream_internal_sb_ctor(this, &fb->base, &fstream_vtable, virt_init);
4846 base = istream_get_ios(&this->base1);
4847 base->delbuf = 1;
4849 return this;
4852 /* ??0fstream@@QAE@H@Z */
4853 /* ??0fstream@@QEAA@H@Z */
4854 DEFINE_THISCALL_WRAPPER(fstream_fd_ctor, 12)
4855 iostream* __thiscall fstream_fd_ctor(iostream *this, filedesc fd, BOOL virt_init)
4857 ios *base;
4858 filebuf *fb = operator_new(sizeof(filebuf));
4860 TRACE("(%p %d %d)\n", this, fd, virt_init);
4862 if (!fb) {
4863 FIXME("out of memory\n");
4864 return NULL;
4867 filebuf_fd_ctor(fb, fd);
4869 iostream_internal_sb_ctor(this, &fb->base, &fstream_vtable, virt_init);
4871 base = istream_get_ios(&this->base1);
4872 base->delbuf = 1;
4874 return this;
4877 /* ??0fstream@@QAE@PBDHH@Z */
4878 /* ??0fstream@@QEAA@PEBDHH@Z */
4879 DEFINE_THISCALL_WRAPPER(fstream_open_ctor, 20)
4880 iostream* __thiscall fstream_open_ctor(iostream *this, const char *name, ios_open_mode mode, int protection, BOOL virt_init)
4882 ios *base;
4883 filebuf *fb = operator_new(sizeof(filebuf));
4885 TRACE("(%p %s %d %d %d)\n", this, name, mode, protection, virt_init);
4887 if (!fb) {
4888 FIXME("out of memory\n");
4889 return NULL;
4892 filebuf_ctor(fb);
4894 iostream_internal_sb_ctor(this, &fb->base, &fstream_vtable, virt_init);
4896 base = istream_get_ios(&this->base1);
4897 base->delbuf = 1;
4899 if (filebuf_open(fb, name, mode, protection) == NULL)
4900 base->state |= IOSTATE_failbit;
4901 return this;
4904 /* ??0fstream@@QAE@XZ */
4905 /* ??0fstream@@QEAA@XZ */
4906 DEFINE_THISCALL_WRAPPER(fstream_ctor, 8)
4907 iostream* __thiscall fstream_ctor(iostream *this, BOOL virt_init)
4909 return fstream_fd_ctor(this, -1, virt_init);
4912 /* ?rdbuf@fstream@@QBEPAVfilebuf@@XZ */
4913 /* ?rdbuf@fstream@@QEBAPEAVfilebuf@@XZ */
4914 DEFINE_THISCALL_WRAPPER(fstream_rdbuf, 4)
4915 filebuf* __thiscall fstream_rdbuf(const iostream *this)
4917 TRACE("(%p)\n", this);
4918 return (filebuf*) istream_get_ios(&this->base1)->sb;
4921 /* ?fd@fstream@@QBEHXZ */
4922 /* ?fd@fstream@@QEBAHXZ */
4923 DEFINE_THISCALL_WRAPPER(fstream_fd, 4)
4924 filedesc __thiscall fstream_fd(iostream *this)
4926 TRACE("(%p)\n", this);
4927 return filebuf_fd(fstream_rdbuf(this));
4930 /* ?attach@fstream@@QAEXH@Z */
4931 /* ?attach@fstream@@QEAAXH@Z */
4932 DEFINE_THISCALL_WRAPPER(fstream_attach, 8)
4933 void __thiscall fstream_attach(iostream *this, filedesc fd)
4935 ios *base = istream_get_ios(&this->base1);
4936 TRACE("(%p %d)\n", this, fd);
4937 if (filebuf_attach(fstream_rdbuf(this), fd) == NULL)
4938 ios_clear(base, base->state | IOSTATE_failbit);
4941 /* ?close@fstream@@QAEXXZ */
4942 /* ?close@fstream@@QEAAXXZ */
4943 DEFINE_THISCALL_WRAPPER(fstream_close, 4)
4944 void __thiscall fstream_close(iostream *this)
4946 ios *base = istream_get_ios(&this->base1);
4947 TRACE("(%p)\n", this);
4948 if (filebuf_close(fstream_rdbuf(this)) == NULL)
4949 ios_clear(base, base->state | IOSTATE_failbit);
4950 else
4951 ios_clear(base, IOSTATE_goodbit);
4954 /* ?is_open@fstream@@QBEHXZ */
4955 /* ?is_open@fstream@@QEBAHXZ */
4956 DEFINE_THISCALL_WRAPPER(fstream_is_open, 4)
4957 int __thiscall fstream_is_open(const iostream *this)
4959 TRACE("(%p)\n", this);
4960 return filebuf_is_open(fstream_rdbuf(this));
4963 /* ?open@fstream@@QAEXPBDHH@Z */
4964 /* ?open@fstream@@QEAAXPEBDHH@Z */
4965 DEFINE_THISCALL_WRAPPER(fstream_open, 16)
4966 void __thiscall fstream_open(iostream *this, const char *name, ios_open_mode mode, int protection)
4968 ios *base = istream_get_ios(&this->base1);
4969 TRACE("(%p %s %d %d)\n", this, name, mode, protection);
4970 if (filebuf_open(fstream_rdbuf(this), name, mode|OPENMODE_out, protection) == NULL)
4971 ios_clear(base, base->state | IOSTATE_failbit);
4974 /* ?setbuf@fstream@@QAEPAVstreambuf@@PADH@Z */
4975 /* ?setbuf@fstream@@QEAAPEAVstreambuf@@PEADH@Z */
4976 DEFINE_THISCALL_WRAPPER(fstream_setbuf, 12)
4977 streambuf* __thiscall fstream_setbuf(iostream *this, char *buffer, int length)
4979 ios *base = istream_get_ios(&this->base1);
4980 filebuf* fb = fstream_rdbuf(this);
4982 TRACE("(%p %p %d)\n", this, buffer, length);
4984 if (filebuf_is_open(fb)) {
4985 ios_clear(base, base->state | IOSTATE_failbit);
4986 return NULL;
4989 return filebuf_setbuf(fb, buffer, length);
4992 /* ?setmode@fstream@@QAEHH@Z */
4993 /* ?setmode@fstream@@QEAAHH@Z */
4994 DEFINE_THISCALL_WRAPPER(fstream_setmode, 8)
4995 int __thiscall fstream_setmode(iostream *this, int mode)
4997 TRACE("(%p %d)\n", this, mode);
4998 return filebuf_setmode(fstream_rdbuf(this), mode);
5001 /* ??0Iostream_init@@QAE@AAVios@@H@Z */
5002 /* ??0Iostream_init@@QEAA@AEAVios@@H@Z */
5003 DEFINE_THISCALL_WRAPPER(Iostream_init_ios_ctor, 12)
5004 void* __thiscall Iostream_init_ios_ctor(void *this, ios *obj, int n)
5006 TRACE("(%p %p %d)\n", this, obj, n);
5007 obj->delbuf = 1;
5008 if (n >= 0) {
5009 obj->tie = &cout.os;
5010 if (n > 0)
5011 ios_setf(obj, FLAGS_unitbuf);
5013 return this;
5016 /* ??0Iostream_init@@QAE@XZ */
5017 /* ??0Iostream_init@@QEAA@XZ */
5018 DEFINE_THISCALL_WRAPPER(Iostream_init_ctor, 4)
5019 void* __thiscall Iostream_init_ctor(void *this)
5021 TRACE("(%p)\n", this);
5022 return this;
5025 /* ??1Iostream_init@@QAE@XZ */
5026 /* ??1Iostream_init@@QEAA@XZ */
5027 DEFINE_THISCALL_WRAPPER(Iostream_init_dtor, 4)
5028 void __thiscall Iostream_init_dtor(void *this)
5030 TRACE("(%p)\n", this);
5033 /* ??4Iostream_init@@QAEAAV0@ABV0@@Z */
5034 /* ??4Iostream_init@@QEAAAEAV0@AEBV0@@Z */
5035 DEFINE_THISCALL_WRAPPER(Iostream_init_assign, 8)
5036 void* __thiscall Iostream_init_assign(void *this, const void *rhs)
5038 TRACE("(%p %p)\n", this, rhs);
5039 return this;
5042 /* ?sync_with_stdio@ios@@SAXXZ */
5043 void __cdecl ios_sync_with_stdio(void)
5045 if (!ios_sunk_with_stdio) {
5046 stdiobuf *new_buf;
5048 TRACE("()\n");
5050 /* run at most once */
5051 ios_sunk_with_stdio++;
5053 /* calls to [io]stream_assign_sb automatically destroy the old buffers */
5054 if ((new_buf = operator_new(sizeof(stdiobuf)))) {
5055 stdiobuf_file_ctor(new_buf, stdin);
5056 istream_assign_sb(&cin.is, &new_buf->base);
5057 } else
5058 istream_assign_sb(&cin.is, NULL);
5059 cin.vbase.delbuf = 1;
5060 ios_setf(&cin.vbase, FLAGS_stdio);
5062 if ((new_buf = operator_new(sizeof(stdiobuf)))) {
5063 stdiobuf_file_ctor(new_buf, stdout);
5064 stdiobuf_setrwbuf(new_buf, 0, 80);
5065 ostream_assign_sb(&cout.os, &new_buf->base);
5066 } else
5067 ostream_assign_sb(&cout.os, NULL);
5068 cout.vbase.delbuf = 1;
5069 ios_setf(&cout.vbase, FLAGS_unitbuf | FLAGS_stdio);
5071 if ((new_buf = operator_new(sizeof(stdiobuf)))) {
5072 stdiobuf_file_ctor(new_buf, stderr);
5073 stdiobuf_setrwbuf(new_buf, 0, 80);
5074 ostream_assign_sb(&cerr.os, &new_buf->base);
5075 } else
5076 ostream_assign_sb(&cerr.os, NULL);
5077 cerr.vbase.delbuf = 1;
5078 ios_setf(&cerr.vbase, FLAGS_unitbuf | FLAGS_stdio);
5080 if ((new_buf = operator_new(sizeof(stdiobuf)))) {
5081 stdiobuf_file_ctor(new_buf, stderr);
5082 stdiobuf_setrwbuf(new_buf, 0, 512);
5083 ostream_assign_sb(&MSVCP_clog.os, &new_buf->base);
5084 } else
5085 ostream_assign_sb(&MSVCP_clog.os, NULL);
5086 MSVCP_clog.vbase.delbuf = 1;
5087 ios_setf(&MSVCP_clog.vbase, FLAGS_stdio);
5092 #ifdef __ASM_USE_THISCALL_WRAPPER
5094 #define DEFINE_VTBL_WRAPPER(off) \
5095 __ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
5096 "popl %eax\n\t" \
5097 "popl %ecx\n\t" \
5098 "pushl %eax\n\t" \
5099 "movl 0(%ecx), %eax\n\t" \
5100 "jmp *" #off "(%eax)\n\t")
5102 DEFINE_VTBL_WRAPPER(0);
5103 DEFINE_VTBL_WRAPPER(4);
5104 DEFINE_VTBL_WRAPPER(8);
5105 DEFINE_VTBL_WRAPPER(12);
5106 DEFINE_VTBL_WRAPPER(16);
5107 DEFINE_VTBL_WRAPPER(20);
5108 DEFINE_VTBL_WRAPPER(24);
5109 DEFINE_VTBL_WRAPPER(28);
5110 DEFINE_VTBL_WRAPPER(32);
5111 DEFINE_VTBL_WRAPPER(36);
5112 DEFINE_VTBL_WRAPPER(40);
5113 DEFINE_VTBL_WRAPPER(44);
5114 DEFINE_VTBL_WRAPPER(48);
5115 DEFINE_VTBL_WRAPPER(52);
5116 DEFINE_VTBL_WRAPPER(56);
5118 #endif
5120 void __cdecl _mtlock(CRITICAL_SECTION *crit)
5122 TRACE("(%p)\n", crit);
5123 EnterCriticalSection(crit);
5126 void __cdecl _mtunlock(CRITICAL_SECTION *crit)
5128 TRACE("(%p)\n", crit);
5129 LeaveCriticalSection(crit);
5132 static void init_cxx_funcs(void)
5134 HMODULE hmod = GetModuleHandleA("msvcrt.dll");
5136 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
5138 operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
5139 operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
5141 else
5143 operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
5144 operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
5148 static void init_io(void *base)
5150 filebuf *fb;
5152 #ifdef __x86_64__
5153 init_streambuf_rtti(base);
5154 init_filebuf_rtti(base);
5155 init_strstreambuf_rtti(base);
5156 init_stdiobuf_rtti(base);
5157 init_ios_rtti(base);
5158 init_ostream_rtti(base);
5159 init_ostream_withassign_rtti(base);
5160 init_ostrstream_rtti(base);
5161 init_ofstream_rtti(base);
5162 init_istream_rtti(base);
5163 init_istream_withassign_rtti(base);
5164 init_istrstream_rtti(base);
5165 init_ifstream_rtti(base);
5166 init_iostream_rtti(base);
5167 init_strstream_rtti(base);
5168 init_stdiostream_rtti(base);
5169 init_fstream_rtti(base);
5170 #endif
5172 if ((fb = operator_new(sizeof(filebuf)))) {
5173 filebuf_fd_ctor(fb, 0);
5174 istream_withassign_sb_ctor(&cin.is, &fb->base, TRUE);
5175 } else
5176 istream_withassign_sb_ctor(&cin.is, NULL, TRUE);
5177 Iostream_init_ios_ctor(NULL, &cin.vbase, 0);
5179 if ((fb = operator_new(sizeof(filebuf)))) {
5180 filebuf_fd_ctor(fb, 1);
5181 ostream_withassign_sb_ctor(&cout.os, &fb->base, TRUE);
5182 } else
5183 ostream_withassign_sb_ctor(&cout.os, NULL, TRUE);
5184 Iostream_init_ios_ctor(NULL, &cout.vbase, -1);
5186 if ((fb = operator_new(sizeof(filebuf)))) {
5187 filebuf_fd_ctor(fb, 2);
5188 ostream_withassign_sb_ctor(&cerr.os, &fb->base, TRUE);
5189 } else
5190 ostream_withassign_sb_ctor(&cerr.os, NULL, TRUE);
5191 Iostream_init_ios_ctor(NULL, &cerr.vbase, 1);
5193 if ((fb = operator_new(sizeof(filebuf)))) {
5194 filebuf_fd_ctor(fb, 2);
5195 ostream_withassign_sb_ctor(&MSVCP_clog.os, &fb->base, TRUE);
5196 } else
5197 ostream_withassign_sb_ctor(&MSVCP_clog.os, NULL, TRUE);
5198 Iostream_init_ios_ctor(NULL, &MSVCP_clog.vbase, 0);
5201 static void free_io(void)
5203 /* destructors take care of deleting the buffers */
5204 istream_vbase_dtor(&cin.is);
5205 ostream_vbase_dtor(&cout.os);
5206 ostream_vbase_dtor(&cerr.os);
5207 ostream_vbase_dtor(&MSVCP_clog.os);
5210 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
5212 switch (reason)
5214 case DLL_PROCESS_ATTACH:
5215 init_cxx_funcs();
5216 init_exception(inst);
5217 init_io(inst);
5218 DisableThreadLibraryCalls( inst );
5219 break;
5220 case DLL_PROCESS_DETACH:
5221 if (reserved) break;
5222 free_io();
5223 break;
5225 return TRUE;