wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / msvcirt / msvcirt.c
blobdb4b736d272e23b986c6c5a5e4ebb88acf2d54e8
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 /* ?sh_none@filebuf@@2HB */
42 const int filebuf_sh_none = 0x800;
43 /* ?sh_read@filebuf@@2HB */
44 const int filebuf_sh_read = 0xa00;
45 /* ?sh_write@filebuf@@2HB */
46 const int filebuf_sh_write = 0xc00;
47 /* ?openprot@filebuf@@2HB */
48 const int filebuf_openprot = 420;
49 /* ?binary@filebuf@@2HB */
50 const int filebuf_binary = _O_BINARY;
51 /* ?text@filebuf@@2HB */
52 const int filebuf_text = _O_TEXT;
54 /* ?adjustfield@ios@@2JB */
55 const LONG ios_adjustfield = FLAGS_left | FLAGS_right | FLAGS_internal;
56 /* ?basefield@ios@@2JB */
57 const LONG ios_basefield = FLAGS_dec | FLAGS_oct | FLAGS_hex;
58 /* ?floatfield@ios@@2JB */
59 const LONG ios_floatfield = FLAGS_scientific | FLAGS_fixed;
60 /* ?fLockcInit@ios@@0HA */
61 int ios_fLockcInit = 0;
62 /* ?sunk_with_stdio@ios@@0HA */
63 int ios_sunk_with_stdio = 0;
64 /* ?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A */
65 extern CRITICAL_SECTION ios_static_lock;
66 CRITICAL_SECTION_DEBUG ios_static_lock_debug =
68 0, 0, &ios_static_lock,
69 { &ios_static_lock_debug.ProcessLocksList, &ios_static_lock_debug.ProcessLocksList },
70 0, 0, { (DWORD_PTR)(__FILE__ ": ios_static_lock") }
72 CRITICAL_SECTION ios_static_lock = { &ios_static_lock_debug, -1, 0, 0, 0, 0 };
73 /* ?x_maxbit@ios@@0JA */
74 LONG ios_maxbit = 0x8000;
75 /* ?x_curindex@ios@@0HA */
76 int ios_curindex = -1;
77 /* ?x_statebuf@ios@@0PAJA */
78 LONG ios_statebuf[STATEBUF_SIZE] = {0};
80 /* class streambuf */
81 typedef struct {
82 const vtable_ptr *vtable;
83 int allocated;
84 int unbuffered;
85 int stored_char;
86 char *base;
87 char *ebuf;
88 char *pbase;
89 char *pptr;
90 char *epptr;
91 char *eback;
92 char *gptr;
93 char *egptr;
94 int do_lock;
95 CRITICAL_SECTION lock;
96 } streambuf;
98 void __thiscall streambuf_setb(streambuf*, char*, char*, int);
99 streambuf* __thiscall streambuf_setbuf(streambuf*, char*, int);
100 void __thiscall streambuf_setg(streambuf*, char*, char*, char*);
101 void __thiscall streambuf_setp(streambuf*, char*, char*);
103 /* class filebuf */
104 typedef struct {
105 streambuf base;
106 filedesc fd;
107 int close;
108 } filebuf;
110 filebuf* __thiscall filebuf_close(filebuf*);
112 /* class strstreambuf */
113 typedef struct {
114 streambuf base;
115 int dynamic;
116 int increase;
117 int unknown;
118 int constant;
119 allocFunction f_alloc;
120 freeFunction f_free;
121 } strstreambuf;
123 /* class stdiobuf */
124 typedef struct {
125 streambuf base;
126 FILE *file;
127 } stdiobuf;
129 /* class ios */
130 struct _ostream;
131 typedef struct {
132 const vtable_ptr *vtable;
133 streambuf *sb;
134 ios_io_state state;
135 int special[4];
136 int delbuf;
137 struct _ostream *tie;
138 ios_flags flags;
139 int precision;
140 char fill;
141 int width;
142 int do_lock;
143 CRITICAL_SECTION lock;
144 } ios;
146 ios* __thiscall ios_assign(ios*, const ios*);
147 int __thiscall ios_fail(const ios*);
148 void __cdecl ios_lock(ios*);
149 void __cdecl ios_lockc(void);
150 LONG __thiscall ios_setf_mask(ios*, LONG, LONG);
151 void __cdecl ios_unlock(ios*);
152 void __cdecl ios_unlockc(void);
154 /* class ostream */
155 typedef struct _ostream {
156 const int *vbtable;
157 int unknown;
158 } ostream;
160 /* class istream */
161 typedef struct {
162 const int *vbtable;
163 int extract_delim;
164 int count;
165 } istream;
167 /* class iostream */
168 typedef struct {
169 istream base1;
170 ostream base2;
171 } iostream;
173 /* ??_7streambuf@@6B@ */
174 extern const vtable_ptr MSVCP_streambuf_vtable;
175 /* ??_7filebuf@@6B@ */
176 extern const vtable_ptr MSVCP_filebuf_vtable;
177 /* ??_7strstreambuf@@6B@ */
178 extern const vtable_ptr MSVCP_strstreambuf_vtable;
179 /* ??_7stdiobuf@@6B@ */
180 extern const vtable_ptr MSVCP_stdiobuf_vtable;
181 /* ??_7ios@@6B@ */
182 extern const vtable_ptr MSVCP_ios_vtable;
183 /* ??_7ostream@@6B@ */
184 extern const vtable_ptr MSVCP_ostream_vtable;
185 /* ??_7ostream_withassign@@6B@ */
186 extern const vtable_ptr MSVCP_ostream_withassign_vtable;
187 /* ??_7ostrstream@@6B@ */
188 extern const vtable_ptr MSVCP_ostrstream_vtable;
189 /* ??_7ofstream@@6B@ */
190 extern const vtable_ptr MSVCP_ofstream_vtable;
191 /* ??_7istream@@6B@ */
192 extern const vtable_ptr MSVCP_istream_vtable;
193 /* ??_7istream_withassign@@6B@ */
194 extern const vtable_ptr MSVCP_istream_withassign_vtable;
195 /* ??_7istrstream@@6B@ */
196 extern const vtable_ptr MSVCP_istrstream_vtable;
197 /* ??_7ifstream@@6B@ */
198 extern const vtable_ptr MSVCP_ifstream_vtable;
199 /* ??_7iostream@@6B@ */
200 extern const vtable_ptr MSVCP_iostream_vtable;
201 /* ??_7strstream@@6B@ */
202 extern const vtable_ptr MSVCP_strstream_vtable;
203 /* ??_7stdiostream@@6B@ */
204 extern const vtable_ptr MSVCP_stdiostream_vtable;
205 /* ??_7fstream@@6B@ */
206 extern const vtable_ptr MSVCP_fstream_vtable;
208 __ASM_BLOCK_BEGIN(vtables)
209 __ASM_VTABLE(streambuf,
210 VTABLE_ADD_FUNC(streambuf_vector_dtor)
211 VTABLE_ADD_FUNC(streambuf_sync)
212 VTABLE_ADD_FUNC(streambuf_setbuf)
213 VTABLE_ADD_FUNC(streambuf_seekoff)
214 VTABLE_ADD_FUNC(streambuf_seekpos)
215 VTABLE_ADD_FUNC(streambuf_xsputn)
216 VTABLE_ADD_FUNC(streambuf_xsgetn)
217 VTABLE_ADD_FUNC(streambuf_overflow)
218 VTABLE_ADD_FUNC(streambuf_underflow)
219 VTABLE_ADD_FUNC(streambuf_pbackfail)
220 VTABLE_ADD_FUNC(streambuf_doallocate));
221 __ASM_VTABLE(filebuf,
222 VTABLE_ADD_FUNC(filebuf_vector_dtor)
223 VTABLE_ADD_FUNC(filebuf_sync)
224 VTABLE_ADD_FUNC(filebuf_setbuf)
225 VTABLE_ADD_FUNC(filebuf_seekoff)
226 VTABLE_ADD_FUNC(streambuf_seekpos)
227 VTABLE_ADD_FUNC(streambuf_xsputn)
228 VTABLE_ADD_FUNC(streambuf_xsgetn)
229 VTABLE_ADD_FUNC(filebuf_overflow)
230 VTABLE_ADD_FUNC(filebuf_underflow)
231 VTABLE_ADD_FUNC(streambuf_pbackfail)
232 VTABLE_ADD_FUNC(streambuf_doallocate));
233 __ASM_VTABLE(strstreambuf,
234 VTABLE_ADD_FUNC(strstreambuf_vector_dtor)
235 VTABLE_ADD_FUNC(strstreambuf_sync)
236 VTABLE_ADD_FUNC(strstreambuf_setbuf)
237 VTABLE_ADD_FUNC(strstreambuf_seekoff)
238 VTABLE_ADD_FUNC(streambuf_seekpos)
239 VTABLE_ADD_FUNC(streambuf_xsputn)
240 VTABLE_ADD_FUNC(streambuf_xsgetn)
241 VTABLE_ADD_FUNC(strstreambuf_overflow)
242 VTABLE_ADD_FUNC(strstreambuf_underflow)
243 VTABLE_ADD_FUNC(streambuf_pbackfail)
244 VTABLE_ADD_FUNC(strstreambuf_doallocate));
245 __ASM_VTABLE(stdiobuf,
246 VTABLE_ADD_FUNC(stdiobuf_vector_dtor)
247 VTABLE_ADD_FUNC(stdiobuf_sync)
248 VTABLE_ADD_FUNC(streambuf_setbuf)
249 VTABLE_ADD_FUNC(stdiobuf_seekoff)
250 VTABLE_ADD_FUNC(streambuf_seekpos)
251 VTABLE_ADD_FUNC(streambuf_xsputn)
252 VTABLE_ADD_FUNC(streambuf_xsgetn)
253 VTABLE_ADD_FUNC(stdiobuf_overflow)
254 VTABLE_ADD_FUNC(stdiobuf_underflow)
255 VTABLE_ADD_FUNC(stdiobuf_pbackfail)
256 VTABLE_ADD_FUNC(streambuf_doallocate));
257 __ASM_VTABLE(ios,
258 VTABLE_ADD_FUNC(ios_vector_dtor));
259 __ASM_VTABLE(ostream,
260 VTABLE_ADD_FUNC(ostream_vector_dtor));
261 __ASM_VTABLE(ostream_withassign,
262 VTABLE_ADD_FUNC(ostream_vector_dtor));
263 __ASM_VTABLE(ostrstream,
264 VTABLE_ADD_FUNC(ostream_vector_dtor));
265 __ASM_VTABLE(ofstream,
266 VTABLE_ADD_FUNC(ostream_vector_dtor));
267 __ASM_VTABLE(istream,
268 VTABLE_ADD_FUNC(istream_vector_dtor));
269 __ASM_VTABLE(istream_withassign,
270 VTABLE_ADD_FUNC(istream_vector_dtor));
271 __ASM_VTABLE(istrstream,
272 VTABLE_ADD_FUNC(istream_vector_dtor));
273 __ASM_VTABLE(ifstream,
274 VTABLE_ADD_FUNC(istream_vector_dtor));
275 __ASM_VTABLE(iostream,
276 VTABLE_ADD_FUNC(iostream_vector_dtor));
277 __ASM_VTABLE(strstream,
278 VTABLE_ADD_FUNC(iostream_vector_dtor));
279 __ASM_VTABLE(stdiostream,
280 VTABLE_ADD_FUNC(iostream_vector_dtor));
281 __ASM_VTABLE(fstream,
282 VTABLE_ADD_FUNC(iostream_vector_dtor));
283 __ASM_BLOCK_END
285 #define ALIGNED_SIZE(size, alignment) (((size)+((alignment)-1))/(alignment)*(alignment))
286 #define VBTABLE_ENTRY(class, offset, vbase) ALIGNED_SIZE(sizeof(class), TYPE_ALIGNMENT(vbase))-offset
288 /* ??_8ostream@@7B@ */
289 /* ??_8ostream_withassign@@7B@ */
290 /* ??_8ostrstream@@7B@ */
291 /* ??_8ofstream@@7B@ */
292 const int ostream_vbtable[] = {0, VBTABLE_ENTRY(ostream, FIELD_OFFSET(ostream, vbtable), ios)};
293 /* ??_8istream@@7B@ */
294 /* ??_8istream_withassign@@7B@ */
295 /* ??_8istrstream@@7B@ */
296 /* ??_8ifstream@@7B@ */
297 const int istream_vbtable[] = {0, VBTABLE_ENTRY(istream, FIELD_OFFSET(istream, vbtable), ios)};
298 /* ??_8iostream@@7Bistream@@@ */
299 /* ??_8stdiostream@@7Bistream@@@ */
300 /* ??_8strstream@@7Bistream@@@ */
301 const int iostream_vbtable_istream[] = {0, VBTABLE_ENTRY(iostream, FIELD_OFFSET(iostream, base1), ios)};
302 /* ??_8iostream@@7Bostream@@@ */
303 /* ??_8stdiostream@@7Bostream@@@ */
304 /* ??_8strstream@@7Bostream@@@ */
305 const int iostream_vbtable_ostream[] = {0, VBTABLE_ENTRY(iostream, FIELD_OFFSET(iostream, base2), ios)};
307 DEFINE_RTTI_DATA0(streambuf, 0, ".?AVstreambuf@@")
308 DEFINE_RTTI_DATA1(filebuf, 0, &streambuf_rtti_base_descriptor, ".?AVfilebuf@@")
309 DEFINE_RTTI_DATA1(strstreambuf, 0, &streambuf_rtti_base_descriptor, ".?AVstrstreambuf@@")
310 DEFINE_RTTI_DATA1(stdiobuf, 0, &streambuf_rtti_base_descriptor, ".?AVstdiobuf@@")
311 DEFINE_RTTI_DATA0(ios, 0, ".?AVios@@")
312 DEFINE_RTTI_DATA1(ostream, sizeof(ostream), &ios_rtti_base_descriptor, ".?AVostream@@")
313 DEFINE_RTTI_DATA2(ostream_withassign, sizeof(ostream),
314 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVostream_withassign@@")
315 DEFINE_RTTI_DATA2(ostrstream, sizeof(ostream),
316 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVostrstream@@")
317 DEFINE_RTTI_DATA2(ofstream, sizeof(ostream),
318 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVofstream@@")
319 DEFINE_RTTI_DATA1(istream, sizeof(istream), &ios_rtti_base_descriptor, ".?AVistream@@")
320 DEFINE_RTTI_DATA2(istream_withassign, sizeof(istream),
321 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVistream_withassign@@")
322 DEFINE_RTTI_DATA2(istrstream, sizeof(istream),
323 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVistrstream@@")
324 DEFINE_RTTI_DATA2(ifstream, sizeof(istream),
325 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVifstream@@")
326 DEFINE_RTTI_DATA4(iostream, sizeof(iostream),
327 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor,
328 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AViostream@@")
329 DEFINE_RTTI_DATA5(strstream, sizeof(iostream), &iostream_rtti_base_descriptor,
330 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor,
331 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVstrstream@@")
332 DEFINE_RTTI_DATA5(stdiostream, sizeof(iostream), &iostream_rtti_base_descriptor,
333 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor,
334 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVstdiostream@@")
335 DEFINE_RTTI_DATA5(fstream, sizeof(iostream), &iostream_rtti_base_descriptor,
336 &istream_rtti_base_descriptor, &ios_rtti_base_descriptor,
337 &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVfstream@@")
339 /* ?cin@@3Vistream_withassign@@A */
340 struct {
341 istream is;
342 ios vbase;
343 } cin = { { 0 } };
345 /* ?cout@@3Vostream_withassign@@A */
346 /* ?cerr@@3Vostream_withassign@@A */
347 /* ?clog@@3Vostream_withassign@@A */
348 struct {
349 ostream os;
350 ios vbase;
351 } cout = { { 0 } }, cerr = { { 0 } }, MSVCP_clog = { { 0 } };
354 /* ??0streambuf@@IAE@PADH@Z */
355 /* ??0streambuf@@IEAA@PEADH@Z */
356 DEFINE_THISCALL_WRAPPER(streambuf_reserve_ctor, 12)
357 streambuf* __thiscall streambuf_reserve_ctor(streambuf *this, char *buffer, int length)
359 TRACE("(%p %p %d)\n", this, buffer, length);
360 this->vtable = &MSVCP_streambuf_vtable;
361 this->allocated = 0;
362 this->stored_char = EOF;
363 this->do_lock = -1;
364 this->base = NULL;
365 streambuf_setbuf(this, buffer, length);
366 streambuf_setg(this, NULL, NULL, NULL);
367 streambuf_setp(this, NULL, NULL);
368 InitializeCriticalSection(&this->lock);
369 return this;
372 /* ??0streambuf@@IAE@XZ */
373 /* ??0streambuf@@IEAA@XZ */
374 DEFINE_THISCALL_WRAPPER(streambuf_ctor, 4)
375 streambuf* __thiscall streambuf_ctor(streambuf *this)
377 streambuf_reserve_ctor(this, NULL, 0);
378 this->unbuffered = 0;
379 return this;
382 /* ??0streambuf@@QAE@ABV0@@Z */
383 /* ??0streambuf@@QEAA@AEBV0@@Z */
384 DEFINE_THISCALL_WRAPPER(streambuf_copy_ctor, 8)
385 streambuf* __thiscall streambuf_copy_ctor(streambuf *this, const streambuf *copy)
387 TRACE("(%p %p)\n", this, copy);
388 *this = *copy;
389 this->vtable = &MSVCP_streambuf_vtable;
390 return this;
393 /* ??1streambuf@@UAE@XZ */
394 /* ??1streambuf@@UEAA@XZ */
395 DEFINE_THISCALL_WRAPPER(streambuf_dtor, 4)
396 void __thiscall streambuf_dtor(streambuf *this)
398 TRACE("(%p)\n", this);
399 if (this->allocated)
400 MSVCRT_operator_delete(this->base);
401 DeleteCriticalSection(&this->lock);
404 /* ??4streambuf@@QAEAAV0@ABV0@@Z */
405 /* ??4streambuf@@QEAAAEAV0@AEBV0@@Z */
406 DEFINE_THISCALL_WRAPPER(streambuf_assign, 8)
407 streambuf* __thiscall streambuf_assign(streambuf *this, const streambuf *rhs)
409 streambuf_dtor(this);
410 return streambuf_copy_ctor(this, rhs);
413 /* ??_Estreambuf@@UAEPAXI@Z */
414 DEFINE_THISCALL_WRAPPER(streambuf_vector_dtor, 8)
415 #define call_streambuf_vector_dtor(this, flags) CALL_VTBL_FUNC(this, 0,\
416 streambuf*, (streambuf*, unsigned int), (this, flags))
417 streambuf* __thiscall streambuf_vector_dtor(streambuf *this, unsigned int flags)
419 TRACE("(%p %x)\n", this, flags);
420 if (flags & 2) {
421 /* we have an array, with the number of elements stored before the first object */
422 INT_PTR i, *ptr = (INT_PTR *)this-1;
424 for (i = *ptr-1; i >= 0; i--)
425 streambuf_dtor(this+i);
426 MSVCRT_operator_delete(ptr);
427 } else {
428 streambuf_dtor(this);
429 if (flags & 1)
430 MSVCRT_operator_delete(this);
432 return this;
435 /* ??_Gstreambuf@@UAEPAXI@Z */
436 DEFINE_THISCALL_WRAPPER(streambuf_scalar_dtor, 8)
437 streambuf* __thiscall streambuf_scalar_dtor(streambuf *this, unsigned int flags)
439 TRACE("(%p %x)\n", this, flags);
440 streambuf_dtor(this);
441 if (flags & 1) MSVCRT_operator_delete(this);
442 return this;
445 /* ?doallocate@streambuf@@MAEHXZ */
446 /* ?doallocate@streambuf@@MEAAHXZ */
447 DEFINE_THISCALL_WRAPPER(streambuf_doallocate, 4)
448 #define call_streambuf_doallocate(this) CALL_VTBL_FUNC(this, 40, int, (streambuf*), (this))
449 int __thiscall streambuf_doallocate(streambuf *this)
451 char *reserve;
453 TRACE("(%p)\n", this);
454 reserve = MSVCRT_operator_new(RESERVE_SIZE);
455 if (!reserve)
456 return EOF;
458 streambuf_setb(this, reserve, reserve + RESERVE_SIZE, 1);
459 return 1;
462 /* ?allocate@streambuf@@IAEHXZ */
463 /* ?allocate@streambuf@@IEAAHXZ */
464 DEFINE_THISCALL_WRAPPER(streambuf_allocate, 4)
465 int __thiscall streambuf_allocate(streambuf *this)
467 TRACE("(%p)\n", this);
468 if (this->base != NULL || this->unbuffered)
469 return 0;
470 return call_streambuf_doallocate(this);
473 /* ?base@streambuf@@IBEPADXZ */
474 /* ?base@streambuf@@IEBAPEADXZ */
475 DEFINE_THISCALL_WRAPPER(streambuf_base, 4)
476 char* __thiscall streambuf_base(const streambuf *this)
478 TRACE("(%p)\n", this);
479 return this->base;
482 /* ?blen@streambuf@@IBEHXZ */
483 /* ?blen@streambuf@@IEBAHXZ */
484 DEFINE_THISCALL_WRAPPER(streambuf_blen, 4)
485 int __thiscall streambuf_blen(const streambuf *this)
487 TRACE("(%p)\n", this);
488 return this->ebuf - this->base;
491 /* ?eback@streambuf@@IBEPADXZ */
492 /* ?eback@streambuf@@IEBAPEADXZ */
493 DEFINE_THISCALL_WRAPPER(streambuf_eback, 4)
494 char* __thiscall streambuf_eback(const streambuf *this)
496 TRACE("(%p)\n", this);
497 return this->eback;
500 /* ?ebuf@streambuf@@IBEPADXZ */
501 /* ?ebuf@streambuf@@IEBAPEADXZ */
502 DEFINE_THISCALL_WRAPPER(streambuf_ebuf, 4)
503 char* __thiscall streambuf_ebuf(const streambuf *this)
505 TRACE("(%p)\n", this);
506 return this->ebuf;
509 /* ?egptr@streambuf@@IBEPADXZ */
510 /* ?egptr@streambuf@@IEBAPEADXZ */
511 DEFINE_THISCALL_WRAPPER(streambuf_egptr, 4)
512 char* __thiscall streambuf_egptr(const streambuf *this)
514 TRACE("(%p)\n", this);
515 return this->egptr;
518 /* ?epptr@streambuf@@IBEPADXZ */
519 /* ?epptr@streambuf@@IEBAPEADXZ */
520 DEFINE_THISCALL_WRAPPER(streambuf_epptr, 4)
521 char* __thiscall streambuf_epptr(const streambuf *this)
523 TRACE("(%p)\n", this);
524 return this->epptr;
527 /* ?gptr@streambuf@@IBEPADXZ */
528 /* ?gptr@streambuf@@IEBAPEADXZ */
529 DEFINE_THISCALL_WRAPPER(streambuf_gptr, 4)
530 char* __thiscall streambuf_gptr(const streambuf *this)
532 TRACE("(%p)\n", this);
533 return this->gptr;
536 /* ?pbase@streambuf@@IBEPADXZ */
537 /* ?pbase@streambuf@@IEBAPEADXZ */
538 DEFINE_THISCALL_WRAPPER(streambuf_pbase, 4)
539 char* __thiscall streambuf_pbase(const streambuf *this)
541 TRACE("(%p)\n", this);
542 return this->pbase;
545 /* ?pptr@streambuf@@IBEPADXZ */
546 /* ?pptr@streambuf@@IEBAPEADXZ */
547 DEFINE_THISCALL_WRAPPER(streambuf_pptr, 4)
548 char* __thiscall streambuf_pptr(const streambuf *this)
550 TRACE("(%p)\n", this);
551 return this->pptr;
554 /* ?clrlock@streambuf@@QAEXXZ */
555 /* ?clrlock@streambuf@@QEAAXXZ */
556 DEFINE_THISCALL_WRAPPER(streambuf_clrlock, 4)
557 void __thiscall streambuf_clrlock(streambuf *this)
559 TRACE("(%p)\n", this);
560 if (this->do_lock <= 0)
561 this->do_lock++;
564 /* ?lock@streambuf@@QAEXXZ */
565 /* ?lock@streambuf@@QEAAXXZ */
566 DEFINE_THISCALL_WRAPPER(streambuf_lock, 4)
567 void __thiscall streambuf_lock(streambuf *this)
569 TRACE("(%p)\n", this);
570 if (this->do_lock < 0)
571 EnterCriticalSection(&this->lock);
574 /* ?lockptr@streambuf@@IAEPAU_CRT_CRITICAL_SECTION@@XZ */
575 /* ?lockptr@streambuf@@IEAAPEAU_CRT_CRITICAL_SECTION@@XZ */
576 DEFINE_THISCALL_WRAPPER(streambuf_lockptr, 4)
577 CRITICAL_SECTION* __thiscall streambuf_lockptr(streambuf *this)
579 TRACE("(%p)\n", this);
580 return &this->lock;
583 /* ?gbump@streambuf@@IAEXH@Z */
584 /* ?gbump@streambuf@@IEAAXH@Z */
585 DEFINE_THISCALL_WRAPPER(streambuf_gbump, 8)
586 void __thiscall streambuf_gbump(streambuf *this, int count)
588 TRACE("(%p %d)\n", this, count);
589 this->gptr += count;
592 /* ?pbump@streambuf@@IAEXH@Z */
593 /* ?pbump@streambuf@@IEAAXH@Z */
594 DEFINE_THISCALL_WRAPPER(streambuf_pbump, 8)
595 void __thiscall streambuf_pbump(streambuf *this, int count)
597 TRACE("(%p %d)\n", this, count);
598 this->pptr += count;
601 /* ?in_avail@streambuf@@QBEHXZ */
602 /* ?in_avail@streambuf@@QEBAHXZ */
603 DEFINE_THISCALL_WRAPPER(streambuf_in_avail, 4)
604 int __thiscall streambuf_in_avail(const streambuf *this)
606 TRACE("(%p)\n", this);
607 return (this->egptr - this->gptr > 0) ? this->egptr - this->gptr : 0;
610 /* ?out_waiting@streambuf@@QBEHXZ */
611 /* ?out_waiting@streambuf@@QEBAHXZ */
612 DEFINE_THISCALL_WRAPPER(streambuf_out_waiting, 4)
613 int __thiscall streambuf_out_waiting(const streambuf *this)
615 TRACE("(%p)\n", this);
616 return (this->pptr - this->pbase > 0) ? this->pptr - this->pbase : 0;
619 /* Unexported */
620 DEFINE_THISCALL_WRAPPER(streambuf_overflow, 8)
621 #define call_streambuf_overflow(this, c) CALL_VTBL_FUNC(this, 28, int, (streambuf*, int), (this, c))
622 int __thiscall streambuf_overflow(streambuf *this, int c)
624 ERR("overflow is not implemented in streambuf\n");
625 return EOF;
628 /* ?seekoff@streambuf@@UAEJJW4seek_dir@ios@@H@Z */
629 /* ?seekoff@streambuf@@UEAAJJW4seek_dir@ios@@H@Z */
630 DEFINE_THISCALL_WRAPPER(streambuf_seekoff, 16)
631 #define call_streambuf_seekoff(this, off, dir, mode) CALL_VTBL_FUNC(this, 12, streampos, (streambuf*, streamoff, ios_seek_dir, int), (this, off, dir, mode))
632 streampos __thiscall streambuf_seekoff(streambuf *this, streamoff offset, ios_seek_dir dir, int mode)
634 TRACE("(%p %d %d %d)\n", this, offset, dir, mode);
635 return EOF;
638 /* ?seekpos@streambuf@@UAEJJH@Z */
639 /* ?seekpos@streambuf@@UEAAJJH@Z */
640 DEFINE_THISCALL_WRAPPER(streambuf_seekpos, 12)
641 streampos __thiscall streambuf_seekpos(streambuf *this, streampos pos, int mode)
643 TRACE("(%p %d %d)\n", this, pos, mode);
644 return call_streambuf_seekoff(this, pos, SEEKDIR_beg, mode);
647 /* ?pbackfail@streambuf@@UAEHH@Z */
648 /* ?pbackfail@streambuf@@UEAAHH@Z */
649 DEFINE_THISCALL_WRAPPER(streambuf_pbackfail, 8)
650 #define call_streambuf_pbackfail(this, c) CALL_VTBL_FUNC(this, 36, int, (streambuf*, int), (this, c))
651 int __thiscall streambuf_pbackfail(streambuf *this, int c)
653 TRACE("(%p %d)\n", this, c);
654 if (this->gptr > this->eback)
655 return *--this->gptr = c;
656 if (call_streambuf_seekoff(this, -1, SEEKDIR_cur, OPENMODE_in) == EOF)
657 return EOF;
658 if (!this->unbuffered && this->egptr) {
659 /* 'c' should be the next character read */
660 memmove(this->gptr + 1, this->gptr, this->egptr - this->gptr - 1);
661 *this->gptr = c;
663 return c;
666 /* ?setb@streambuf@@IAEXPAD0H@Z */
667 /* ?setb@streambuf@@IEAAXPEAD0H@Z */
668 DEFINE_THISCALL_WRAPPER(streambuf_setb, 16)
669 void __thiscall streambuf_setb(streambuf *this, char *ba, char *eb, int delete)
671 TRACE("(%p %p %p %d)\n", this, ba, eb, delete);
672 if (this->allocated)
673 MSVCRT_operator_delete(this->base);
674 this->allocated = delete;
675 this->base = ba;
676 this->ebuf = eb;
679 /* ?setbuf@streambuf@@UAEPAV1@PADH@Z */
680 /* ?setbuf@streambuf@@UEAAPEAV1@PEADH@Z */
681 DEFINE_THISCALL_WRAPPER(streambuf_setbuf, 12)
682 streambuf* __thiscall streambuf_setbuf(streambuf *this, char *buffer, int length)
684 TRACE("(%p %p %d)\n", this, buffer, length);
685 if (this->base != NULL)
686 return NULL;
688 if (buffer == NULL || !length) {
689 this->unbuffered = 1;
690 this->base = this->ebuf = NULL;
691 } else {
692 this->unbuffered = 0;
693 this->base = buffer;
694 this->ebuf = buffer + length;
696 return this;
699 /* ?setg@streambuf@@IAEXPAD00@Z */
700 /* ?setg@streambuf@@IEAAXPEAD00@Z */
701 DEFINE_THISCALL_WRAPPER(streambuf_setg, 16)
702 void __thiscall streambuf_setg(streambuf *this, char *ek, char *gp, char *eg)
704 TRACE("(%p %p %p %p)\n", this, ek, gp, eg);
705 this->eback = ek;
706 this->gptr = gp;
707 this->egptr = eg;
710 /* ?setlock@streambuf@@QAEXXZ */
711 /* ?setlock@streambuf@@QEAAXXZ */
712 DEFINE_THISCALL_WRAPPER(streambuf_setlock, 4)
713 void __thiscall streambuf_setlock(streambuf *this)
715 TRACE("(%p)\n", this);
716 this->do_lock--;
719 /* ?setp@streambuf@@IAEXPAD0@Z */
720 /* ?setp@streambuf@@IEAAXPEAD0@Z */
721 DEFINE_THISCALL_WRAPPER(streambuf_setp, 12)
722 void __thiscall streambuf_setp(streambuf *this, char *pb, char *ep)
724 TRACE("(%p %p %p)\n", this, pb, ep);
725 this->pbase = this->pptr = pb;
726 this->epptr = ep;
729 /* ?sync@streambuf@@UAEHXZ */
730 /* ?sync@streambuf@@UEAAHXZ */
731 DEFINE_THISCALL_WRAPPER(streambuf_sync, 4)
732 #define call_streambuf_sync(this) CALL_VTBL_FUNC(this, 4, int, (streambuf*), (this))
733 int __thiscall streambuf_sync(streambuf *this)
735 TRACE("(%p)\n", this);
736 return (this->gptr >= this->egptr && this->pbase >= this->pptr) ? 0 : EOF;
739 /* ?unbuffered@streambuf@@IAEXH@Z */
740 /* ?unbuffered@streambuf@@IEAAXH@Z */
741 DEFINE_THISCALL_WRAPPER(streambuf_unbuffered_set, 8)
742 void __thiscall streambuf_unbuffered_set(streambuf *this, int buf)
744 TRACE("(%p %d)\n", this, buf);
745 this->unbuffered = buf;
748 /* ?unbuffered@streambuf@@IBEHXZ */
749 /* ?unbuffered@streambuf@@IEBAHXZ */
750 DEFINE_THISCALL_WRAPPER(streambuf_unbuffered_get, 4)
751 int __thiscall streambuf_unbuffered_get(const streambuf *this)
753 TRACE("(%p)\n", this);
754 return this->unbuffered;
757 /* Unexported */
758 DEFINE_THISCALL_WRAPPER(streambuf_underflow, 4)
759 #define call_streambuf_underflow(this) CALL_VTBL_FUNC(this, 32, int, (streambuf*), (this))
760 int __thiscall streambuf_underflow(streambuf *this)
762 ERR("underflow is not implemented in streambuf\n");
763 return EOF;
766 /* ?unlock@streambuf@@QAEXXZ */
767 /* ?unlock@streambuf@@QEAAXXZ */
768 DEFINE_THISCALL_WRAPPER(streambuf_unlock, 4)
769 void __thiscall streambuf_unlock(streambuf *this)
771 TRACE("(%p)\n", this);
772 if (this->do_lock < 0)
773 LeaveCriticalSection(&this->lock);
776 /* ?xsgetn@streambuf@@UAEHPADH@Z */
777 /* ?xsgetn@streambuf@@UEAAHPEADH@Z */
778 DEFINE_THISCALL_WRAPPER(streambuf_xsgetn, 12)
779 #define call_streambuf_xsgetn(this, buffer, count) CALL_VTBL_FUNC(this, 24, int, (streambuf*, char*, int), (this, buffer, count))
780 int __thiscall streambuf_xsgetn(streambuf *this, char *buffer, int count)
782 int copied = 0, chunk;
784 TRACE("(%p %p %d)\n", this, buffer, count);
786 if (this->unbuffered) {
787 if (this->stored_char == EOF)
788 this->stored_char = call_streambuf_underflow(this);
789 while (copied < count && this->stored_char != EOF) {
790 buffer[copied++] = this->stored_char;
791 this->stored_char = call_streambuf_underflow(this);
793 } else {
794 while (copied < count) {
795 if (call_streambuf_underflow(this) == EOF)
796 break;
797 chunk = this->egptr - this->gptr;
798 if (chunk > count - copied)
799 chunk = count - copied;
800 memcpy(buffer+copied, this->gptr, chunk);
801 this->gptr += chunk;
802 copied += chunk;
805 return copied;
808 /* ?xsputn@streambuf@@UAEHPBDH@Z */
809 /* ?xsputn@streambuf@@UEAAHPEBDH@Z */
810 DEFINE_THISCALL_WRAPPER(streambuf_xsputn, 12)
811 #define call_streambuf_xsputn(this, data, length) CALL_VTBL_FUNC(this, 20, int, (streambuf*, const char*, int), (this, data, length))
812 int __thiscall streambuf_xsputn(streambuf *this, const char *data, int length)
814 int copied = 0, chunk;
816 TRACE("(%p %p %d)\n", this, data, length);
818 while (copied < length) {
819 if (this->unbuffered || this->pptr == this->epptr) {
820 if (call_streambuf_overflow(this, data[copied]) == EOF)
821 break;
822 copied++;
823 } else {
824 chunk = this->epptr - this->pptr;
825 if (chunk > length - copied)
826 chunk = length - copied;
827 memcpy(this->pptr, data+copied, chunk);
828 this->pptr += chunk;
829 copied += chunk;
832 return copied;
835 /* ?sgetc@streambuf@@QAEHXZ */
836 /* ?sgetc@streambuf@@QEAAHXZ */
837 DEFINE_THISCALL_WRAPPER(streambuf_sgetc, 4)
838 int __thiscall streambuf_sgetc(streambuf *this)
840 TRACE("(%p)\n", this);
841 if (this->unbuffered) {
842 if (this->stored_char == EOF)
843 this->stored_char = call_streambuf_underflow(this);
844 return this->stored_char;
845 } else
846 return call_streambuf_underflow(this);
849 /* ?sputc@streambuf@@QAEHH@Z */
850 /* ?sputc@streambuf@@QEAAHH@Z */
851 DEFINE_THISCALL_WRAPPER(streambuf_sputc, 8)
852 int __thiscall streambuf_sputc(streambuf *this, int ch)
854 TRACE("(%p %d)\n", this, ch);
855 return (this->pptr < this->epptr) ? (unsigned char)(*this->pptr++ = ch) : call_streambuf_overflow(this, ch);
858 /* ?sgetn@streambuf@@QAEHPADH@Z */
859 /* ?sgetn@streambuf@@QEAAHPEADH@Z */
860 DEFINE_THISCALL_WRAPPER(streambuf_sgetn, 12)
861 int __thiscall streambuf_sgetn(streambuf *this, char *buffer, int count)
863 return call_streambuf_xsgetn(this, buffer, count);
866 /* ?sputn@streambuf@@QAEHPBDH@Z */
867 /* ?sputn@streambuf@@QEAAHPEBDH@Z */
868 DEFINE_THISCALL_WRAPPER(streambuf_sputn, 12)
869 int __thiscall streambuf_sputn(streambuf *this, const char *data, int length)
871 return call_streambuf_xsputn(this, data, length);
874 /* ?snextc@streambuf@@QAEHXZ */
875 /* ?snextc@streambuf@@QEAAHXZ */
876 DEFINE_THISCALL_WRAPPER(streambuf_snextc, 4)
877 int __thiscall streambuf_snextc(streambuf *this)
879 TRACE("(%p)\n", this);
880 if (this->unbuffered) {
881 if (this->stored_char == EOF)
882 call_streambuf_underflow(this);
883 return this->stored_char = call_streambuf_underflow(this);
884 } else {
885 if (this->gptr >= this->egptr)
886 call_streambuf_underflow(this);
887 this->gptr++;
888 return (this->gptr < this->egptr) ? (unsigned char)(*this->gptr) : call_streambuf_underflow(this);
892 /* ?sbumpc@streambuf@@QAEHXZ */
893 /* ?sbumpc@streambuf@@QEAAHXZ */
894 DEFINE_THISCALL_WRAPPER(streambuf_sbumpc, 4)
895 int __thiscall streambuf_sbumpc(streambuf *this)
897 int ret;
899 TRACE("(%p)\n", this);
901 if (this->unbuffered) {
902 ret = this->stored_char;
903 this->stored_char = EOF;
904 if (ret == EOF)
905 ret = call_streambuf_underflow(this);
906 } else {
907 ret = (this->gptr < this->egptr) ? (unsigned char)(*this->gptr) : call_streambuf_underflow(this);
908 this->gptr++;
910 return ret;
913 /* ?stossc@streambuf@@QAEXXZ */
914 /* ?stossc@streambuf@@QEAAXXZ */
915 DEFINE_THISCALL_WRAPPER(streambuf_stossc, 4)
916 void __thiscall streambuf_stossc(streambuf *this)
918 TRACE("(%p)\n", this);
919 if (this->unbuffered) {
920 if (this->stored_char == EOF)
921 call_streambuf_underflow(this);
922 else
923 this->stored_char = EOF;
924 } else {
925 if (this->gptr >= this->egptr)
926 call_streambuf_underflow(this);
927 if (this->gptr < this->egptr)
928 this->gptr++;
932 /* ?sputbackc@streambuf@@QAEHD@Z */
933 /* ?sputbackc@streambuf@@QEAAHD@Z */
934 DEFINE_THISCALL_WRAPPER(streambuf_sputbackc, 8)
935 int __thiscall streambuf_sputbackc(streambuf *this, char ch)
937 TRACE("(%p %d)\n", this, ch);
938 return call_streambuf_pbackfail(this, ch);
941 /* ?dbp@streambuf@@QAEXXZ */
942 /* ?dbp@streambuf@@QEAAXXZ */
943 DEFINE_THISCALL_WRAPPER(streambuf_dbp, 4)
944 void __thiscall streambuf_dbp(streambuf *this)
946 printf("\nSTREAMBUF DEBUG INFO: this=%p, ", this);
947 if (this->unbuffered) {
948 printf("unbuffered\n");
949 } else {
950 printf("_fAlloc=%d\n", this->allocated);
951 printf(" base()=%p, ebuf()=%p, blen()=%d\n", this->base, this->ebuf, streambuf_blen(this));
952 printf("pbase()=%p, pptr()=%p, epptr()=%p\n", this->pbase, this->pptr, this->epptr);
953 printf("eback()=%p, gptr()=%p, egptr()=%p\n", this->eback, this->gptr, this->egptr);
957 /* ??0filebuf@@QAE@ABV0@@Z */
958 /* ??0filebuf@@QEAA@AEBV0@@Z */
959 DEFINE_THISCALL_WRAPPER(filebuf_copy_ctor, 8)
960 filebuf* __thiscall filebuf_copy_ctor(filebuf* this, const filebuf *copy)
962 TRACE("(%p %p)\n", this, copy);
963 *this = *copy;
964 this->base.vtable = &MSVCP_filebuf_vtable;
965 return this;
968 /* ??0filebuf@@QAE@HPADH@Z */
969 /* ??0filebuf@@QEAA@HPEADH@Z */
970 DEFINE_THISCALL_WRAPPER(filebuf_fd_reserve_ctor, 16)
971 filebuf* __thiscall filebuf_fd_reserve_ctor(filebuf* this, filedesc fd, char *buffer, int length)
973 TRACE("(%p %d %p %d)\n", this, fd, buffer, length);
974 streambuf_reserve_ctor(&this->base, buffer, length);
975 this->base.vtable = &MSVCP_filebuf_vtable;
976 this->fd = fd;
977 this->close = 0;
978 return this;
981 /* ??0filebuf@@QAE@H@Z */
982 /* ??0filebuf@@QEAA@H@Z */
983 DEFINE_THISCALL_WRAPPER(filebuf_fd_ctor, 8)
984 filebuf* __thiscall filebuf_fd_ctor(filebuf* this, filedesc fd)
986 filebuf_fd_reserve_ctor(this, fd, NULL, 0);
987 this->base.unbuffered = 0;
988 return this;
991 /* ??0filebuf@@QAE@XZ */
992 /* ??0filebuf@@QEAA@XZ */
993 DEFINE_THISCALL_WRAPPER(filebuf_ctor, 4)
994 filebuf* __thiscall filebuf_ctor(filebuf* this)
996 return filebuf_fd_ctor(this, -1);
999 /* ??1filebuf@@UAE@XZ */
1000 /* ??1filebuf@@UEAA@XZ */
1001 DEFINE_THISCALL_WRAPPER(filebuf_dtor, 4)
1002 void __thiscall filebuf_dtor(filebuf* this)
1004 TRACE("(%p)\n", this);
1005 if (this->close)
1006 filebuf_close(this);
1007 streambuf_dtor(&this->base);
1010 /* ??4filebuf@@QAEAAV0@ABV0@@Z */
1011 /* ??4filebuf@@QEAAAEAV0@AEBV0@@Z */
1012 DEFINE_THISCALL_WRAPPER(filebuf_assign, 8)
1013 filebuf* __thiscall filebuf_assign(filebuf* this, const filebuf *rhs)
1015 filebuf_dtor(this);
1016 return filebuf_copy_ctor(this, rhs);
1019 /* ??_Efilebuf@@UAEPAXI@Z */
1020 DEFINE_THISCALL_WRAPPER(filebuf_vector_dtor, 8)
1021 filebuf* __thiscall filebuf_vector_dtor(filebuf *this, unsigned int flags)
1023 TRACE("(%p %x)\n", this, flags);
1024 if (flags & 2) {
1025 /* we have an array, with the number of elements stored before the first object */
1026 INT_PTR i, *ptr = (INT_PTR *)this-1;
1028 for (i = *ptr-1; i >= 0; i--)
1029 filebuf_dtor(this+i);
1030 MSVCRT_operator_delete(ptr);
1031 } else {
1032 filebuf_dtor(this);
1033 if (flags & 1)
1034 MSVCRT_operator_delete(this);
1036 return this;
1039 /* ??_Gfilebuf@@UAEPAXI@Z */
1040 DEFINE_THISCALL_WRAPPER(filebuf_scalar_dtor, 8)
1041 filebuf* __thiscall filebuf_scalar_dtor(filebuf *this, unsigned int flags)
1043 TRACE("(%p %x)\n", this, flags);
1044 filebuf_dtor(this);
1045 if (flags & 1) MSVCRT_operator_delete(this);
1046 return this;
1049 /* ?attach@filebuf@@QAEPAV1@H@Z */
1050 /* ?attach@filebuf@@QEAAPEAV1@H@Z */
1051 DEFINE_THISCALL_WRAPPER(filebuf_attach, 8)
1052 filebuf* __thiscall filebuf_attach(filebuf *this, filedesc fd)
1054 TRACE("(%p %d)\n", this, fd);
1055 if (this->fd != -1)
1056 return NULL;
1058 streambuf_lock(&this->base);
1059 this->fd = fd;
1060 streambuf_allocate(&this->base);
1061 streambuf_unlock(&this->base);
1062 return this;
1065 /* ?close@filebuf@@QAEPAV1@XZ */
1066 /* ?close@filebuf@@QEAAPEAV1@XZ */
1067 DEFINE_THISCALL_WRAPPER(filebuf_close, 4)
1068 filebuf* __thiscall filebuf_close(filebuf *this)
1070 filebuf *ret;
1072 TRACE("(%p)\n", this);
1073 if (this->fd == -1)
1074 return NULL;
1076 streambuf_lock(&this->base);
1077 if (call_streambuf_sync(&this->base) == EOF || _close(this->fd) < 0) {
1078 ret = NULL;
1079 } else {
1080 this->fd = -1;
1081 ret = this;
1083 streambuf_unlock(&this->base);
1084 return ret;
1087 /* ?fd@filebuf@@QBEHXZ */
1088 /* ?fd@filebuf@@QEBAHXZ */
1089 DEFINE_THISCALL_WRAPPER(filebuf_fd, 4)
1090 filedesc __thiscall filebuf_fd(const filebuf *this)
1092 TRACE("(%p)\n", this);
1093 return this->fd;
1096 /* ?is_open@filebuf@@QBEHXZ */
1097 /* ?is_open@filebuf@@QEBAHXZ */
1098 DEFINE_THISCALL_WRAPPER(filebuf_is_open, 4)
1099 int __thiscall filebuf_is_open(const filebuf *this)
1101 TRACE("(%p)\n", this);
1102 return this->fd != -1;
1105 /* ?open@filebuf@@QAEPAV1@PBDHH@Z */
1106 /* ?open@filebuf@@QEAAPEAV1@PEBDHH@Z */
1107 DEFINE_THISCALL_WRAPPER(filebuf_open, 16)
1108 filebuf* __thiscall filebuf_open(filebuf *this, const char *name, ios_open_mode mode, int protection)
1110 const int inout_mode[4] = {-1, _O_RDONLY, _O_WRONLY, _O_RDWR};
1111 const int share_mode[4] = {_SH_DENYRW, _SH_DENYWR, _SH_DENYRD, _SH_DENYNO};
1112 int op_flags, sh_flags, fd;
1114 TRACE("(%p %s %x %x)\n", this, name, mode, protection);
1115 if (this->fd != -1)
1116 return NULL;
1118 /* mode */
1119 if (mode & (OPENMODE_app|OPENMODE_trunc))
1120 mode |= OPENMODE_out;
1121 op_flags = inout_mode[mode & (OPENMODE_in|OPENMODE_out)];
1122 if (op_flags < 0)
1123 return NULL;
1124 if (mode & OPENMODE_app)
1125 op_flags |= _O_APPEND;
1126 if ((mode & OPENMODE_trunc) ||
1127 ((mode & OPENMODE_out) && !(mode & (OPENMODE_in|OPENMODE_app|OPENMODE_ate))))
1128 op_flags |= _O_TRUNC;
1129 if (!(mode & OPENMODE_nocreate))
1130 op_flags |= _O_CREAT;
1131 if (mode & OPENMODE_noreplace)
1132 op_flags |= _O_EXCL;
1133 op_flags |= (mode & OPENMODE_binary) ? _O_BINARY : _O_TEXT;
1135 /* share protection */
1136 sh_flags = (protection & filebuf_sh_none) ? share_mode[(protection >> 9) & 3] : _SH_DENYNO;
1138 TRACE("op_flags %x, sh_flags %x\n", op_flags, sh_flags);
1139 fd = _sopen(name, op_flags, sh_flags, _S_IREAD|_S_IWRITE);
1140 if (fd < 0)
1141 return NULL;
1143 streambuf_lock(&this->base);
1144 this->close = 1;
1145 this->fd = fd;
1146 if ((mode & OPENMODE_ate) &&
1147 call_streambuf_seekoff(&this->base, 0, SEEKDIR_end, mode & (OPENMODE_in|OPENMODE_out)) == EOF) {
1148 _close(fd);
1149 this->fd = -1;
1151 streambuf_allocate(&this->base);
1152 streambuf_unlock(&this->base);
1153 return (this->fd == -1) ? NULL : this;
1156 /* ?overflow@filebuf@@UAEHH@Z */
1157 /* ?overflow@filebuf@@UEAAHH@Z */
1158 DEFINE_THISCALL_WRAPPER(filebuf_overflow, 8)
1159 int __thiscall filebuf_overflow(filebuf *this, int c)
1161 TRACE("(%p %d)\n", this, c);
1162 if (call_streambuf_sync(&this->base) == EOF)
1163 return EOF;
1164 if (this->base.unbuffered)
1165 return (c == EOF) ? 1 : _write(this->fd, &c, 1);
1166 if (streambuf_allocate(&this->base) == EOF)
1167 return EOF;
1169 this->base.pbase = this->base.pptr = this->base.base;
1170 this->base.epptr = this->base.ebuf;
1171 if (c != EOF)
1172 *this->base.pptr++ = c;
1173 return 1;
1176 /* ?seekoff@filebuf@@UAEJJW4seek_dir@ios@@H@Z */
1177 /* ?seekoff@filebuf@@UEAAJJW4seek_dir@ios@@H@Z */
1178 DEFINE_THISCALL_WRAPPER(filebuf_seekoff, 16)
1179 streampos __thiscall filebuf_seekoff(filebuf *this, streamoff offset, ios_seek_dir dir, int mode)
1181 TRACE("(%p %d %d %d)\n", this, offset, dir, mode);
1182 if (call_streambuf_sync(&this->base) == EOF)
1183 return EOF;
1184 return _lseek(this->fd, offset, dir);
1187 /* ?setbuf@filebuf@@UAEPAVstreambuf@@PADH@Z */
1188 /* ?setbuf@filebuf@@UEAAPEAVstreambuf@@PEADH@Z */
1189 DEFINE_THISCALL_WRAPPER(filebuf_setbuf, 12)
1190 streambuf* __thiscall filebuf_setbuf(filebuf *this, char *buffer, int length)
1192 TRACE("(%p %p %d)\n", this, buffer, length);
1194 if (filebuf_is_open(this) && this->base.base != NULL)
1195 return NULL;
1197 streambuf_lock(&this->base);
1199 if (buffer == NULL || !length) {
1200 this->base.unbuffered = 1;
1201 } else {
1202 if (this->base.allocated) {
1203 MSVCRT_operator_delete(this->base.base);
1204 this->base.allocated = 0;
1207 this->base.base = buffer;
1208 this->base.ebuf = buffer + length;
1211 streambuf_unlock(&this->base);
1213 return &this->base;
1216 /* ?setmode@filebuf@@QAEHH@Z */
1217 /* ?setmode@filebuf@@QEAAHH@Z */
1218 DEFINE_THISCALL_WRAPPER(filebuf_setmode, 8)
1219 int __thiscall filebuf_setmode(filebuf *this, int mode)
1221 int ret;
1223 TRACE("(%p %d)\n", this, mode);
1224 if (mode != filebuf_text && mode != filebuf_binary)
1225 return -1;
1227 streambuf_lock(&this->base);
1228 ret = (call_streambuf_sync(&this->base) == EOF) ? -1 : _setmode(this->fd, mode);
1229 streambuf_unlock(&this->base);
1230 return ret;
1233 /* ?sync@filebuf@@UAEHXZ */
1234 /* ?sync@filebuf@@UEAAHXZ */
1235 DEFINE_THISCALL_WRAPPER(filebuf_sync, 4)
1236 int __thiscall filebuf_sync(filebuf *this)
1238 int count, mode;
1239 char *ptr;
1240 LONG offset;
1242 TRACE("(%p)\n", this);
1243 if (this->fd == -1)
1244 return EOF;
1245 if (this->base.unbuffered)
1246 return 0;
1248 /* flush output buffer */
1249 if (this->base.pptr != NULL) {
1250 count = this->base.pptr - this->base.pbase;
1251 if (count > 0 && _write(this->fd, this->base.pbase, count) != count)
1252 return EOF;
1254 this->base.pbase = this->base.pptr = this->base.epptr = NULL;
1255 /* flush input buffer */
1256 if (this->base.egptr != NULL) {
1257 offset = this->base.egptr - this->base.gptr;
1258 if (offset > 0) {
1259 mode = _setmode(this->fd, _O_TEXT);
1260 _setmode(this->fd, mode);
1261 if (mode & _O_TEXT) {
1262 /* in text mode, '\n' in the buffer means '\r\n' in the file */
1263 for (ptr = this->base.gptr; ptr < this->base.egptr; ptr++)
1264 if (*ptr == '\n')
1265 offset++;
1267 if (_lseek(this->fd, -offset, SEEK_CUR) < 0)
1268 return EOF;
1271 this->base.eback = this->base.gptr = this->base.egptr = NULL;
1272 return 0;
1275 /* ?underflow@filebuf@@UAEHXZ */
1276 /* ?underflow@filebuf@@UEAAHXZ */
1277 DEFINE_THISCALL_WRAPPER(filebuf_underflow, 4)
1278 int __thiscall filebuf_underflow(filebuf *this)
1280 int buffer_size, read_bytes;
1281 char c;
1283 TRACE("(%p)\n", this);
1285 if (this->base.unbuffered)
1286 return (_read(this->fd, &c, 1) < 1) ? EOF : (unsigned char) c;
1288 if (this->base.gptr >= this->base.egptr) {
1289 if (call_streambuf_sync(&this->base) == EOF)
1290 return EOF;
1291 buffer_size = this->base.ebuf - this->base.base;
1292 read_bytes = _read(this->fd, this->base.base, buffer_size);
1293 if (read_bytes <= 0)
1294 return EOF;
1295 this->base.eback = this->base.gptr = this->base.base;
1296 this->base.egptr = this->base.base + read_bytes;
1298 return (unsigned char) *this->base.gptr;
1301 /* ??0strstreambuf@@QAE@ABV0@@Z */
1302 /* ??0strstreambuf@@QEAA@AEBV0@@Z */
1303 DEFINE_THISCALL_WRAPPER(strstreambuf_copy_ctor, 8)
1304 strstreambuf* __thiscall strstreambuf_copy_ctor(strstreambuf *this, const strstreambuf *copy)
1306 TRACE("(%p %p)\n", this, copy);
1307 *this = *copy;
1308 this->base.vtable = &MSVCP_strstreambuf_vtable;
1309 return this;
1312 /* ??0strstreambuf@@QAE@H@Z */
1313 /* ??0strstreambuf@@QEAA@H@Z */
1314 DEFINE_THISCALL_WRAPPER(strstreambuf_dynamic_ctor, 8)
1315 strstreambuf* __thiscall strstreambuf_dynamic_ctor(strstreambuf* this, int length)
1317 TRACE("(%p %d)\n", this, length);
1318 streambuf_ctor(&this->base);
1319 this->base.vtable = &MSVCP_strstreambuf_vtable;
1320 this->dynamic = 1;
1321 this->increase = length;
1322 this->constant = 0;
1323 this->f_alloc = NULL;
1324 this->f_free = NULL;
1325 return this;
1328 /* ??0strstreambuf@@QAE@P6APAXJ@ZP6AXPAX@Z@Z */
1329 /* ??0strstreambuf@@QEAA@P6APEAXJ@ZP6AXPEAX@Z@Z */
1330 DEFINE_THISCALL_WRAPPER(strstreambuf_funcs_ctor, 12)
1331 strstreambuf* __thiscall strstreambuf_funcs_ctor(strstreambuf* this, allocFunction falloc, freeFunction ffree)
1333 TRACE("(%p %p %p)\n", this, falloc, ffree);
1334 strstreambuf_dynamic_ctor(this, 1);
1335 this->f_alloc = falloc;
1336 this->f_free = ffree;
1337 return this;
1340 /* ??0strstreambuf@@QAE@PADH0@Z */
1341 /* ??0strstreambuf@@QEAA@PEADH0@Z */
1342 DEFINE_THISCALL_WRAPPER(strstreambuf_buffer_ctor, 16)
1343 strstreambuf* __thiscall strstreambuf_buffer_ctor(strstreambuf *this, char *buffer, int length, char *put)
1345 char *end_buffer;
1347 TRACE("(%p %p %d %p)\n", this, buffer, length, put);
1349 if (length > 0)
1350 end_buffer = buffer + length;
1351 else if (length == 0)
1352 end_buffer = buffer + strlen(buffer);
1353 else
1354 end_buffer = (char*) -1;
1356 streambuf_ctor(&this->base);
1357 streambuf_setb(&this->base, buffer, end_buffer, 0);
1358 if (put == NULL) {
1359 streambuf_setg(&this->base, buffer, buffer, end_buffer);
1360 } else {
1361 streambuf_setg(&this->base, buffer, buffer, put);
1362 streambuf_setp(&this->base, put, end_buffer);
1364 this->base.vtable = &MSVCP_strstreambuf_vtable;
1365 this->dynamic = 0;
1366 this->constant = 1;
1367 return this;
1370 /* ??0strstreambuf@@QAE@PAEH0@Z */
1371 /* ??0strstreambuf@@QEAA@PEAEH0@Z */
1372 DEFINE_THISCALL_WRAPPER(strstreambuf_ubuffer_ctor, 16)
1373 strstreambuf* __thiscall strstreambuf_ubuffer_ctor(strstreambuf *this, unsigned char *buffer, int length, unsigned char *put)
1375 TRACE("(%p %p %d %p)\n", this, buffer, length, put);
1376 return strstreambuf_buffer_ctor(this, (char*)buffer, length, (char*)put);
1379 /* ??0strstreambuf@@QAE@XZ */
1380 /* ??0strstreambuf@@QEAA@XZ */
1381 DEFINE_THISCALL_WRAPPER(strstreambuf_ctor, 4)
1382 strstreambuf* __thiscall strstreambuf_ctor(strstreambuf *this)
1384 TRACE("(%p)\n", this);
1385 return strstreambuf_dynamic_ctor(this, 1);
1388 /* ??1strstreambuf@@UAE@XZ */
1389 /* ??1strstreambuf@@UEAA@XZ */
1390 DEFINE_THISCALL_WRAPPER(strstreambuf_dtor, 4)
1391 void __thiscall strstreambuf_dtor(strstreambuf *this)
1393 TRACE("(%p)\n", this);
1394 if (this->dynamic && this->base.base) {
1395 if (this->f_free)
1396 this->f_free(this->base.base);
1397 else
1398 MSVCRT_operator_delete(this->base.base);
1400 streambuf_dtor(&this->base);
1403 /* ??4strstreambuf@@QAEAAV0@ABV0@@Z */
1404 /* ??4strstreambuf@@QEAAAEAV0@AEBV0@@Z */
1405 DEFINE_THISCALL_WRAPPER(strstreambuf_assign, 8)
1406 strstreambuf* __thiscall strstreambuf_assign(strstreambuf *this, const strstreambuf *rhs)
1408 strstreambuf_dtor(this);
1409 return strstreambuf_copy_ctor(this, rhs);
1412 /* ??_Estrstreambuf@@UAEPAXI@Z */
1413 DEFINE_THISCALL_WRAPPER(strstreambuf_vector_dtor, 8)
1414 strstreambuf* __thiscall strstreambuf_vector_dtor(strstreambuf *this, unsigned int flags)
1416 TRACE("(%p %x)\n", this, flags);
1417 if (flags & 2) {
1418 /* we have an array, with the number of elements stored before the first object */
1419 INT_PTR i, *ptr = (INT_PTR *)this-1;
1421 for (i = *ptr-1; i >= 0; i--)
1422 strstreambuf_dtor(this+i);
1423 MSVCRT_operator_delete(ptr);
1424 } else {
1425 strstreambuf_dtor(this);
1426 if (flags & 1)
1427 MSVCRT_operator_delete(this);
1429 return this;
1432 /* ??_Gstrstreambuf@@UAEPAXI@Z */
1433 DEFINE_THISCALL_WRAPPER(strstreambuf_scalar_dtor, 8)
1434 strstreambuf* __thiscall strstreambuf_scalar_dtor(strstreambuf *this, unsigned int flags)
1436 TRACE("(%p %x)\n", this, flags);
1437 strstreambuf_dtor(this);
1438 if (flags & 1) MSVCRT_operator_delete(this);
1439 return this;
1442 /* ?doallocate@strstreambuf@@MAEHXZ */
1443 /* ?doallocate@strstreambuf@@MEAAHXZ */
1444 DEFINE_THISCALL_WRAPPER(strstreambuf_doallocate, 4)
1445 int __thiscall strstreambuf_doallocate(strstreambuf *this)
1447 char *prev_buffer = this->base.base, *new_buffer;
1448 LONG prev_size = this->base.ebuf - this->base.base, new_size;
1450 TRACE("(%p)\n", this);
1452 /* calculate the size of the new buffer */
1453 new_size = (prev_size > 0 ? prev_size : 0) + (this->increase > 0 ? this->increase : 1);
1454 /* get a new buffer */
1455 if (this->f_alloc)
1456 new_buffer = this->f_alloc(new_size);
1457 else
1458 new_buffer = MSVCRT_operator_new(new_size);
1459 if (!new_buffer)
1460 return EOF;
1461 if (this->base.ebuf) {
1462 /* copy the contents and adjust the pointers */
1463 memcpy(new_buffer, this->base.base, prev_size);
1464 if (this->base.egptr) {
1465 this->base.eback += new_buffer - prev_buffer;
1466 this->base.gptr += new_buffer - prev_buffer;
1467 this->base.egptr += new_buffer - prev_buffer;
1469 if (this->base.epptr) {
1470 this->base.pbase += new_buffer - prev_buffer;
1471 this->base.pptr += new_buffer - prev_buffer;
1472 this->base.epptr += new_buffer - prev_buffer;
1474 /* free the old buffer */
1475 if (this->f_free)
1476 this->f_free(this->base.base);
1477 else
1478 MSVCRT_operator_delete(this->base.base);
1480 streambuf_setb(&this->base, new_buffer, new_buffer + new_size, 0);
1481 return 1;
1484 /* ?freeze@strstreambuf@@QAEXH@Z */
1485 /* ?freeze@strstreambuf@@QEAAXH@Z */
1486 DEFINE_THISCALL_WRAPPER(strstreambuf_freeze, 8)
1487 void __thiscall strstreambuf_freeze(strstreambuf *this, int frozen)
1489 TRACE("(%p %d)\n", this, frozen);
1490 if (!this->constant)
1491 this->dynamic = !frozen;
1494 /* ?overflow@strstreambuf@@UAEHH@Z */
1495 /* ?overflow@strstreambuf@@UEAAHH@Z */
1496 DEFINE_THISCALL_WRAPPER(strstreambuf_overflow, 8)
1497 int __thiscall strstreambuf_overflow(strstreambuf *this, int c)
1499 TRACE("(%p %d)\n", this, c);
1500 if (this->base.pptr >= this->base.epptr) {
1501 /* increase the buffer size if it's dynamic */
1502 if (!this->dynamic || call_streambuf_doallocate(&this->base) == EOF)
1503 return EOF;
1504 if (!this->base.epptr)
1505 this->base.pbase = this->base.pptr = this->base.egptr ? this->base.egptr : this->base.base;
1506 this->base.epptr = this->base.ebuf;
1508 if (c != EOF)
1509 *this->base.pptr++ = c;
1510 return 1;
1513 /* ?seekoff@strstreambuf@@UAEJJW4seek_dir@ios@@H@Z */
1514 /* ?seekoff@strstreambuf@@UEAAJJW4seek_dir@ios@@H@Z */
1515 DEFINE_THISCALL_WRAPPER(strstreambuf_seekoff, 16)
1516 streampos __thiscall strstreambuf_seekoff(strstreambuf *this, streamoff offset, ios_seek_dir dir, int mode)
1518 char *base[3];
1520 TRACE("(%p %d %d %d)\n", this, offset, dir, mode);
1522 if ((unsigned int)dir > SEEKDIR_end || !(mode & (OPENMODE_in|OPENMODE_out)))
1523 return EOF;
1524 /* read buffer */
1525 if (mode & OPENMODE_in) {
1526 call_streambuf_underflow(&this->base);
1527 base[SEEKDIR_beg] = this->base.eback;
1528 base[SEEKDIR_cur] = this->base.gptr;
1529 base[SEEKDIR_end] = this->base.egptr;
1530 if (base[dir] + offset < this->base.eback || base[dir] + offset > this->base.egptr)
1531 return EOF;
1532 this->base.gptr = base[dir] + offset;
1534 /* write buffer */
1535 if (mode & OPENMODE_out) {
1536 if (!this->base.epptr && call_streambuf_overflow(&this->base, EOF) == EOF)
1537 return EOF;
1538 base[SEEKDIR_beg] = this->base.pbase;
1539 base[SEEKDIR_cur] = this->base.pptr;
1540 base[SEEKDIR_end] = this->base.epptr;
1541 if (base[dir] + offset < this->base.pbase)
1542 return EOF;
1543 if (base[dir] + offset > this->base.epptr) {
1544 /* make room if the buffer is dynamic */
1545 if (!this->dynamic)
1546 return EOF;
1547 this->increase = offset;
1548 if (call_streambuf_doallocate(&this->base) == EOF)
1549 return EOF;
1551 this->base.pptr = base[dir] + offset;
1552 return this->base.pptr - base[SEEKDIR_beg];
1554 return this->base.gptr - base[SEEKDIR_beg];
1557 /* ?setbuf@strstreambuf@@UAEPAVstreambuf@@PADH@Z */
1558 /* ?setbuf@strstreambuf@@UEAAPEAVstreambuf@@PEADH@Z */
1559 DEFINE_THISCALL_WRAPPER(strstreambuf_setbuf, 12)
1560 streambuf* __thiscall strstreambuf_setbuf(strstreambuf *this, char *buffer, int length)
1562 TRACE("(%p %p %d)\n", this, buffer, length);
1563 if (length)
1564 this->increase = length;
1565 return &this->base;
1568 /* ?str@strstreambuf@@QAEPADXZ */
1569 /* ?str@strstreambuf@@QEAAPEADXZ */
1570 DEFINE_THISCALL_WRAPPER(strstreambuf_str, 4)
1571 char* __thiscall strstreambuf_str(strstreambuf *this)
1573 TRACE("(%p)\n", this);
1574 strstreambuf_freeze(this, 1);
1575 return this->base.base;
1578 /* ?sync@strstreambuf@@UAEHXZ */
1579 /* ?sync@strstreambuf@@UEAAHXZ */
1580 DEFINE_THISCALL_WRAPPER(strstreambuf_sync, 4)
1581 int __thiscall strstreambuf_sync(strstreambuf *this)
1583 TRACE("(%p)\n", this);
1584 return 0;
1587 /* ?underflow@strstreambuf@@UAEHXZ */
1588 /* ?underflow@strstreambuf@@UEAAHXZ */
1589 DEFINE_THISCALL_WRAPPER(strstreambuf_underflow, 4)
1590 int __thiscall strstreambuf_underflow(strstreambuf *this)
1592 TRACE("(%p)\n", this);
1593 if (this->base.gptr < this->base.egptr)
1594 return (unsigned char) *this->base.gptr;
1595 /* extend the get area to include the characters written */
1596 if (this->base.egptr < this->base.pptr) {
1597 this->base.gptr = this->base.base + (this->base.gptr - this->base.eback);
1598 this->base.eback = this->base.base;
1599 this->base.egptr = this->base.pptr;
1601 return (this->base.gptr < this->base.egptr) ? (unsigned char)(*this->base.gptr) : EOF;
1604 /* ??0stdiobuf@@QAE@ABV0@@Z */
1605 /* ??0stdiobuf@@QEAA@AEBV0@@Z */
1606 DEFINE_THISCALL_WRAPPER(stdiobuf_copy_ctor, 8)
1607 stdiobuf* __thiscall stdiobuf_copy_ctor(stdiobuf *this, const stdiobuf *copy)
1609 TRACE("(%p %p)\n", this, copy);
1610 *this = *copy;
1611 this->base.vtable = &MSVCP_stdiobuf_vtable;
1612 return this;
1615 /* ??0stdiobuf@@QAE@PAU_iobuf@@@Z */
1616 /* ??0stdiobuf@@QEAA@PEAU_iobuf@@@Z */
1617 DEFINE_THISCALL_WRAPPER(stdiobuf_file_ctor, 8)
1618 stdiobuf* __thiscall stdiobuf_file_ctor(stdiobuf *this, FILE *file)
1620 TRACE("(%p %p)\n", this, file);
1621 streambuf_reserve_ctor(&this->base, NULL, 0);
1622 this->base.vtable = &MSVCP_stdiobuf_vtable;
1623 this->file = file;
1624 return this;
1627 /* ??1stdiobuf@@UAE@XZ */
1628 /* ??1stdiobuf@@UEAA@XZ */
1629 DEFINE_THISCALL_WRAPPER(stdiobuf_dtor, 4)
1630 void __thiscall stdiobuf_dtor(stdiobuf *this)
1632 TRACE("(%p)\n", this);
1633 call_streambuf_sync(&this->base);
1634 streambuf_dtor(&this->base);
1637 /* ??4stdiobuf@@QAEAAV0@ABV0@@Z */
1638 /* ??4stdiobuf@@QEAAAEAV0@AEBV0@@Z */
1639 DEFINE_THISCALL_WRAPPER(stdiobuf_assign, 8)
1640 stdiobuf* __thiscall stdiobuf_assign(stdiobuf *this, const stdiobuf *rhs)
1642 stdiobuf_dtor(this);
1643 return stdiobuf_copy_ctor(this, rhs);
1646 /* ??_Estdiobuf@@UAEPAXI@Z */
1647 DEFINE_THISCALL_WRAPPER(stdiobuf_vector_dtor, 8)
1648 stdiobuf* __thiscall stdiobuf_vector_dtor(stdiobuf *this, unsigned int flags)
1650 TRACE("(%p %x)\n", this, flags);
1651 if (flags & 2) {
1652 /* we have an array, with the number of elements stored before the first object */
1653 INT_PTR i, *ptr = (INT_PTR *)this-1;
1655 for (i = *ptr-1; i >= 0; i--)
1656 stdiobuf_dtor(this+i);
1657 MSVCRT_operator_delete(ptr);
1658 } else {
1659 stdiobuf_dtor(this);
1660 if (flags & 1)
1661 MSVCRT_operator_delete(this);
1663 return this;
1666 /* ??_Gstdiobuf@@UAEPAXI@Z */
1667 DEFINE_THISCALL_WRAPPER(stdiobuf_scalar_dtor, 8)
1668 stdiobuf* __thiscall stdiobuf_scalar_dtor(stdiobuf *this, unsigned int flags)
1670 TRACE("(%p %x)\n", this, flags);
1671 stdiobuf_dtor(this);
1672 if (flags & 1) MSVCRT_operator_delete(this);
1673 return this;
1676 /* ?overflow@stdiobuf@@UAEHH@Z */
1677 /* ?overflow@stdiobuf@@UEAAHH@Z */
1678 DEFINE_THISCALL_WRAPPER(stdiobuf_overflow, 8)
1679 int __thiscall stdiobuf_overflow(stdiobuf *this, int c)
1681 TRACE("(%p %d)\n", this, c);
1682 if (this->base.unbuffered)
1683 return (c == EOF) ? 1 : fputc(c, this->file);
1684 if (streambuf_allocate(&this->base) == EOF)
1685 return EOF;
1687 if (!this->base.epptr) {
1688 /* set the put area to the second half of the buffer */
1689 streambuf_setp(&this->base,
1690 this->base.base + (this->base.ebuf - this->base.base) / 2, this->base.ebuf);
1691 } else if (this->base.pptr > this->base.pbase) {
1692 /* flush the put area */
1693 int count = this->base.pptr - this->base.pbase;
1694 if (fwrite(this->base.pbase, sizeof(char), count, this->file) != count)
1695 return EOF;
1696 this->base.pptr = this->base.pbase;
1698 if (c != EOF) {
1699 if (this->base.pbase >= this->base.epptr)
1700 return fputc(c, this->file);
1701 *this->base.pptr++ = c;
1703 return 1;
1706 /* ?pbackfail@stdiobuf@@UAEHH@Z */
1707 /* ?pbackfail@stdiobuf@@UEAAHH@Z */
1708 DEFINE_THISCALL_WRAPPER(stdiobuf_pbackfail, 8)
1709 int __thiscall stdiobuf_pbackfail(stdiobuf *this, int c)
1711 TRACE("(%p %d)\n", this, c);
1712 return streambuf_pbackfail(&this->base, c);
1715 /* ?seekoff@stdiobuf@@UAEJJW4seek_dir@ios@@H@Z */
1716 /* ?seekoff@stdiobuf@@UEAAJJW4seek_dir@ios@@H@Z */
1717 DEFINE_THISCALL_WRAPPER(stdiobuf_seekoff, 16)
1718 streampos __thiscall stdiobuf_seekoff(stdiobuf *this, streamoff offset, ios_seek_dir dir, int mode)
1720 TRACE("(%p %d %d %d)\n", this, offset, dir, mode);
1721 call_streambuf_overflow(&this->base, EOF);
1722 if (fseek(this->file, offset, dir))
1723 return EOF;
1724 return ftell(this->file);
1727 /* ?setrwbuf@stdiobuf@@QAEHHH@Z */
1728 /* ?setrwbuf@stdiobuf@@QEAAHHH@Z */
1729 DEFINE_THISCALL_WRAPPER(stdiobuf_setrwbuf, 12)
1730 int __thiscall stdiobuf_setrwbuf(stdiobuf *this, int read_size, int write_size)
1732 char *reserve;
1733 int buffer_size = read_size + write_size;
1735 TRACE("(%p %d %d)\n", this, read_size, write_size);
1736 if (read_size < 0 || write_size < 0)
1737 return 0;
1738 if (!buffer_size) {
1739 this->base.unbuffered = 1;
1740 return 0;
1742 /* get a new buffer */
1743 reserve = MSVCRT_operator_new(buffer_size);
1744 if (!reserve)
1745 return 0;
1746 streambuf_setb(&this->base, reserve, reserve + buffer_size, 1);
1747 this->base.unbuffered = 0;
1748 /* set the get/put areas */
1749 if (read_size > 0)
1750 streambuf_setg(&this->base, reserve, reserve + read_size, reserve + read_size);
1751 else
1752 streambuf_setg(&this->base, NULL, NULL, NULL);
1753 if (write_size > 0)
1754 streambuf_setp(&this->base, reserve + read_size, reserve + buffer_size);
1755 else
1756 streambuf_setp(&this->base, NULL, NULL);
1757 return 1;
1760 /* ?stdiofile@stdiobuf@@QAEPAU_iobuf@@XZ */
1761 /* ?stdiofile@stdiobuf@@QEAAPEAU_iobuf@@XZ */
1762 DEFINE_THISCALL_WRAPPER(stdiobuf_stdiofile, 4)
1763 FILE* __thiscall stdiobuf_stdiofile(stdiobuf *this)
1765 TRACE("(%p)\n", this);
1766 return this->file;
1769 /* ?sync@stdiobuf@@UAEHXZ */
1770 /* ?sync@stdiobuf@@UEAAHXZ */
1771 DEFINE_THISCALL_WRAPPER(stdiobuf_sync, 4)
1772 int __thiscall stdiobuf_sync(stdiobuf *this)
1774 TRACE("(%p)\n", this);
1775 if (this->base.unbuffered)
1776 return 0;
1777 /* flush the put area */
1778 if (call_streambuf_overflow(&this->base, EOF) == EOF)
1779 return EOF;
1780 /* flush the get area */
1781 if (this->base.gptr < this->base.egptr) {
1782 char *ptr;
1783 int fd, mode, offset = this->base.egptr - this->base.gptr;
1784 if ((fd = fileno(this->file)) < 0)
1785 return EOF;
1786 mode = _setmode(fd, _O_TEXT);
1787 _setmode(fd, mode);
1788 if (mode & _O_TEXT) {
1789 /* in text mode, '\n' in the buffer means '\r\n' in the file */
1790 for (ptr = this->base.gptr; ptr < this->base.egptr; ptr++)
1791 if (*ptr == '\n')
1792 offset++;
1794 if (fseek(this->file, -offset, SEEK_CUR))
1795 return EOF;
1796 this->base.gptr = this->base.egptr;
1798 return 0;
1801 /* ?underflow@stdiobuf@@UAEHXZ */
1802 /* ?underflow@stdiobuf@@UEAAHXZ */
1803 DEFINE_THISCALL_WRAPPER(stdiobuf_underflow, 4)
1804 int __thiscall stdiobuf_underflow(stdiobuf *this)
1806 TRACE("(%p)\n", this);
1807 if (!this->file)
1808 return EOF;
1809 if (this->base.unbuffered)
1810 return fgetc(this->file);
1811 if (streambuf_allocate(&this->base) == EOF)
1812 return EOF;
1814 if (!this->base.egptr) {
1815 /* set the get area to the first half of the buffer */
1816 char *middle = this->base.base + (this->base.ebuf - this->base.base) / 2;
1817 streambuf_setg(&this->base, this->base.base, middle, middle);
1819 if (this->base.gptr >= this->base.egptr) {
1820 /* read characters from the file */
1821 int buffer_size = this->base.egptr - this->base.eback, read_bytes;
1822 if (!this->base.eback ||
1823 (read_bytes = fread(this->base.eback, sizeof(char), buffer_size, this->file)) <= 0)
1824 return EOF;
1825 memmove(this->base.egptr - read_bytes, this->base.eback, read_bytes);
1826 this->base.gptr = this->base.egptr - read_bytes;
1828 return (unsigned char) *this->base.gptr++;
1831 /* ??0ios@@IAE@ABV0@@Z */
1832 /* ??0ios@@IEAA@AEBV0@@Z */
1833 DEFINE_THISCALL_WRAPPER(ios_copy_ctor, 8)
1834 ios* __thiscall ios_copy_ctor(ios *this, const ios *copy)
1836 TRACE("(%p %p)\n", this, copy);
1837 ios_fLockcInit++;
1838 this->vtable = &MSVCP_ios_vtable;
1839 this->sb = NULL;
1840 this->delbuf = 0;
1841 this->do_lock = -1;
1842 InitializeCriticalSection(&this->lock);
1843 return ios_assign(this, copy);
1846 /* ??0ios@@QAE@PAVstreambuf@@@Z */
1847 /* ??0ios@@QEAA@PEAVstreambuf@@@Z */
1848 DEFINE_THISCALL_WRAPPER(ios_sb_ctor, 8)
1849 ios* __thiscall ios_sb_ctor(ios *this, streambuf *sb)
1851 TRACE("(%p %p)\n", this, sb);
1852 ios_fLockcInit++;
1853 this->vtable = &MSVCP_ios_vtable;
1854 this->sb = sb;
1855 this->state = sb ? IOSTATE_goodbit : IOSTATE_badbit;
1856 this->special[0] = this->special[1] = 0;
1857 this->delbuf = 0;
1858 this->tie = NULL;
1859 this->flags = 0;
1860 this->precision = 6;
1861 this->fill = ' ';
1862 this->width = 0;
1863 this->do_lock = -1;
1864 InitializeCriticalSection(&this->lock);
1865 return this;
1868 /* ??0ios@@IAE@XZ */
1869 /* ??0ios@@IEAA@XZ */
1870 DEFINE_THISCALL_WRAPPER(ios_ctor, 4)
1871 ios* __thiscall ios_ctor(ios *this)
1873 return ios_sb_ctor(this, NULL);
1876 /* ??1ios@@UAE@XZ */
1877 /* ??1ios@@UEAA@XZ */
1878 DEFINE_THISCALL_WRAPPER(ios_dtor, 4)
1879 void __thiscall ios_dtor(ios *this)
1881 TRACE("(%p)\n", this);
1882 ios_fLockcInit--;
1883 if (this->delbuf && this->sb)
1884 call_streambuf_vector_dtor(this->sb, 1);
1885 this->sb = NULL;
1886 this->state = IOSTATE_badbit;
1887 DeleteCriticalSection(&this->lock);
1890 /* ??4ios@@IAEAAV0@ABV0@@Z */
1891 /* ??4ios@@IEAAAEAV0@AEBV0@@Z */
1892 DEFINE_THISCALL_WRAPPER(ios_assign, 8)
1893 ios* __thiscall ios_assign(ios *this, const ios *rhs)
1895 TRACE("(%p %p)\n", this, rhs);
1896 this->state = rhs->state;
1897 if (!this->sb)
1898 this->state |= IOSTATE_badbit;
1899 this->tie = rhs->tie;
1900 this->flags = rhs->flags;
1901 this->precision = (char) rhs->precision;
1902 this->fill = rhs->fill;
1903 this->width = (char) rhs->width;
1904 return this;
1907 /* ??7ios@@QBEHXZ */
1908 /* ??7ios@@QEBAHXZ */
1909 DEFINE_THISCALL_WRAPPER(ios_op_not, 4)
1910 int __thiscall ios_op_not(const ios *this)
1912 TRACE("(%p)\n", this);
1913 return ios_fail(this);
1916 /* ??Bios@@QBEPAXXZ */
1917 /* ??Bios@@QEBAPEAXXZ */
1918 DEFINE_THISCALL_WRAPPER(ios_op_void, 4)
1919 void* __thiscall ios_op_void(const ios *this)
1921 TRACE("(%p)\n", this);
1922 return ios_fail(this) ? NULL : (void*)this;
1925 /* ??_Eios@@UAEPAXI@Z */
1926 DEFINE_THISCALL_WRAPPER(ios_vector_dtor, 8)
1927 ios* __thiscall ios_vector_dtor(ios *this, unsigned int flags)
1929 TRACE("(%p %x)\n", this, flags);
1930 if (flags & 2) {
1931 /* we have an array, with the number of elements stored before the first object */
1932 INT_PTR i, *ptr = (INT_PTR *)this-1;
1934 for (i = *ptr-1; i >= 0; i--)
1935 ios_dtor(this+i);
1936 MSVCRT_operator_delete(ptr);
1937 } else {
1938 ios_dtor(this);
1939 if (flags & 1)
1940 MSVCRT_operator_delete(this);
1942 return this;
1945 /* ??_Gios@@UAEPAXI@Z */
1946 DEFINE_THISCALL_WRAPPER(ios_scalar_dtor, 8)
1947 ios* __thiscall ios_scalar_dtor(ios *this, unsigned int flags)
1949 TRACE("(%p %x)\n", this, flags);
1950 ios_dtor(this);
1951 if (flags & 1) MSVCRT_operator_delete(this);
1952 return this;
1955 /* ?bad@ios@@QBEHXZ */
1956 /* ?bad@ios@@QEBAHXZ */
1957 DEFINE_THISCALL_WRAPPER(ios_bad, 4)
1958 int __thiscall ios_bad(const ios *this)
1960 TRACE("(%p)\n", this);
1961 return (this->state & IOSTATE_badbit);
1964 /* ?bitalloc@ios@@SAJXZ */
1965 LONG __cdecl ios_bitalloc(void)
1967 TRACE("()\n");
1968 ios_lockc();
1969 ios_maxbit <<= 1;
1970 ios_unlockc();
1971 return ios_maxbit;
1974 /* ?clear@ios@@QAEXH@Z */
1975 /* ?clear@ios@@QEAAXH@Z */
1976 DEFINE_THISCALL_WRAPPER(ios_clear, 8)
1977 void __thiscall ios_clear(ios *this, int state)
1979 TRACE("(%p %d)\n", this, state);
1980 ios_lock(this);
1981 this->state = state;
1982 ios_unlock(this);
1985 /* ?clrlock@ios@@QAAXXZ */
1986 /* ?clrlock@ios@@QEAAXXZ */
1987 void __cdecl ios_clrlock(ios *this)
1989 TRACE("(%p)\n", this);
1990 if (this->do_lock <= 0)
1991 this->do_lock++;
1992 if (this->sb)
1993 streambuf_clrlock(this->sb);
1996 /* ?delbuf@ios@@QAEXH@Z */
1997 /* ?delbuf@ios@@QEAAXH@Z */
1998 DEFINE_THISCALL_WRAPPER(ios_delbuf_set, 8)
1999 void __thiscall ios_delbuf_set(ios *this, int delete)
2001 TRACE("(%p %d)\n", this, delete);
2002 this->delbuf = delete;
2005 /* ?delbuf@ios@@QBEHXZ */
2006 /* ?delbuf@ios@@QEBAHXZ */
2007 DEFINE_THISCALL_WRAPPER(ios_delbuf_get, 4)
2008 int __thiscall ios_delbuf_get(const ios *this)
2010 TRACE("(%p)\n", this);
2011 return this->delbuf;
2014 /* ?dec@@YAAAVios@@AAV1@@Z */
2015 /* ?dec@@YAAEAVios@@AEAV1@@Z */
2016 ios* __cdecl ios_dec(ios *this)
2018 TRACE("(%p)\n", this);
2019 ios_setf_mask(this, FLAGS_dec, ios_basefield);
2020 return this;
2023 /* ?eof@ios@@QBEHXZ */
2024 /* ?eof@ios@@QEBAHXZ */
2025 DEFINE_THISCALL_WRAPPER(ios_eof, 4)
2026 int __thiscall ios_eof(const ios *this)
2028 TRACE("(%p)\n", this);
2029 return (this->state & IOSTATE_eofbit);
2032 /* ?fail@ios@@QBEHXZ */
2033 /* ?fail@ios@@QEBAHXZ */
2034 DEFINE_THISCALL_WRAPPER(ios_fail, 4)
2035 int __thiscall ios_fail(const ios *this)
2037 TRACE("(%p)\n", this);
2038 return (this->state & (IOSTATE_failbit|IOSTATE_badbit));
2041 /* ?fill@ios@@QAEDD@Z */
2042 /* ?fill@ios@@QEAADD@Z */
2043 DEFINE_THISCALL_WRAPPER(ios_fill_set, 8)
2044 char __thiscall ios_fill_set(ios *this, char fill)
2046 char prev = this->fill;
2048 TRACE("(%p %d)\n", this, fill);
2050 this->fill = fill;
2051 return prev;
2054 /* ?fill@ios@@QBEDXZ */
2055 /* ?fill@ios@@QEBADXZ */
2056 DEFINE_THISCALL_WRAPPER(ios_fill_get, 4)
2057 char __thiscall ios_fill_get(const ios *this)
2059 TRACE("(%p)\n", this);
2060 return this->fill;
2063 /* ?flags@ios@@QAEJJ@Z */
2064 /* ?flags@ios@@QEAAJJ@Z */
2065 DEFINE_THISCALL_WRAPPER(ios_flags_set, 8)
2066 LONG __thiscall ios_flags_set(ios *this, LONG flags)
2068 LONG prev = this->flags;
2070 TRACE("(%p %x)\n", this, flags);
2072 this->flags = flags;
2073 return prev;
2076 /* ?flags@ios@@QBEJXZ */
2077 /* ?flags@ios@@QEBAJXZ */
2078 DEFINE_THISCALL_WRAPPER(ios_flags_get, 4)
2079 LONG __thiscall ios_flags_get(const ios *this)
2081 TRACE("(%p)\n", this);
2082 return this->flags;
2085 /* ?good@ios@@QBEHXZ */
2086 /* ?good@ios@@QEBAHXZ */
2087 DEFINE_THISCALL_WRAPPER(ios_good, 4)
2088 int __thiscall ios_good(const ios *this)
2090 TRACE("(%p)\n", this);
2091 return this->state == IOSTATE_goodbit;
2094 /* ?hex@@YAAAVios@@AAV1@@Z */
2095 /* ?hex@@YAAEAVios@@AEAV1@@Z */
2096 ios* __cdecl ios_hex(ios *this)
2098 TRACE("(%p)\n", this);
2099 ios_setf_mask(this, FLAGS_hex, ios_basefield);
2100 return this;
2103 /* ?init@ios@@IAEXPAVstreambuf@@@Z */
2104 /* ?init@ios@@IEAAXPEAVstreambuf@@@Z */
2105 DEFINE_THISCALL_WRAPPER(ios_init, 8)
2106 void __thiscall ios_init(ios *this, streambuf *sb)
2108 TRACE("(%p %p)\n", this, sb);
2109 if (this->delbuf && this->sb)
2110 call_streambuf_vector_dtor(this->sb, 1);
2111 this->sb = sb;
2112 if (sb == NULL)
2113 this->state |= IOSTATE_badbit;
2114 else
2115 this->state &= ~IOSTATE_badbit;
2118 /* ?iword@ios@@QBEAAJH@Z */
2119 /* ?iword@ios@@QEBAAEAJH@Z */
2120 DEFINE_THISCALL_WRAPPER(ios_iword, 8)
2121 LONG* __thiscall ios_iword(const ios *this, int index)
2123 TRACE("(%p %d)\n", this, index);
2124 return &ios_statebuf[index];
2127 /* ?lock@ios@@QAAXXZ */
2128 /* ?lock@ios@@QEAAXXZ */
2129 void __cdecl ios_lock(ios *this)
2131 TRACE("(%p)\n", this);
2132 if (this->do_lock < 0)
2133 EnterCriticalSection(&this->lock);
2136 /* ?lockbuf@ios@@QAAXXZ */
2137 /* ?lockbuf@ios@@QEAAXXZ */
2138 void __cdecl ios_lockbuf(ios *this)
2140 TRACE("(%p)\n", this);
2141 streambuf_lock(this->sb);
2144 /* ?lockc@ios@@KAXXZ */
2145 void __cdecl ios_lockc(void)
2147 TRACE("()\n");
2148 EnterCriticalSection(&ios_static_lock);
2151 /* ?lockptr@ios@@IAEPAU_CRT_CRITICAL_SECTION@@XZ */
2152 /* ?lockptr@ios@@IEAAPEAU_CRT_CRITICAL_SECTION@@XZ */
2153 DEFINE_THISCALL_WRAPPER(ios_lockptr, 4)
2154 CRITICAL_SECTION* __thiscall ios_lockptr(ios *this)
2156 TRACE("(%p)\n", this);
2157 return &this->lock;
2160 /* ?oct@@YAAAVios@@AAV1@@Z */
2161 /* ?oct@@YAAEAVios@@AEAV1@@Z */
2162 ios* __cdecl ios_oct(ios *this)
2164 TRACE("(%p)\n", this);
2165 ios_setf_mask(this, FLAGS_oct, ios_basefield);
2166 return this;
2169 /* ?precision@ios@@QAEHH@Z */
2170 /* ?precision@ios@@QEAAHH@Z */
2171 DEFINE_THISCALL_WRAPPER(ios_precision_set, 8)
2172 int __thiscall ios_precision_set(ios *this, int prec)
2174 int prev = this->precision;
2176 TRACE("(%p %d)\n", this, prec);
2178 this->precision = prec;
2179 return prev;
2182 /* ?precision@ios@@QBEHXZ */
2183 /* ?precision@ios@@QEBAHXZ */
2184 DEFINE_THISCALL_WRAPPER(ios_precision_get, 4)
2185 int __thiscall ios_precision_get(const ios *this)
2187 TRACE("(%p)\n", this);
2188 return this->precision;
2191 /* ?pword@ios@@QBEAAPAXH@Z */
2192 /* ?pword@ios@@QEBAAEAPEAXH@Z */
2193 DEFINE_THISCALL_WRAPPER(ios_pword, 8)
2194 void** __thiscall ios_pword(const ios *this, int index)
2196 TRACE("(%p %d)\n", this, index);
2197 return (void**)&ios_statebuf[index];
2200 /* ?rdbuf@ios@@QBEPAVstreambuf@@XZ */
2201 /* ?rdbuf@ios@@QEBAPEAVstreambuf@@XZ */
2202 DEFINE_THISCALL_WRAPPER(ios_rdbuf, 4)
2203 streambuf* __thiscall ios_rdbuf(const ios *this)
2205 TRACE("(%p)\n", this);
2206 return this->sb;
2209 /* ?rdstate@ios@@QBEHXZ */
2210 /* ?rdstate@ios@@QEBAHXZ */
2211 DEFINE_THISCALL_WRAPPER(ios_rdstate, 4)
2212 int __thiscall ios_rdstate(const ios *this)
2214 TRACE("(%p)\n", this);
2215 return this->state;
2218 /* ?setf@ios@@QAEJJ@Z */
2219 /* ?setf@ios@@QEAAJJ@Z */
2220 DEFINE_THISCALL_WRAPPER(ios_setf, 8)
2221 LONG __thiscall ios_setf(ios *this, LONG flags)
2223 LONG prev = this->flags;
2225 TRACE("(%p %x)\n", this, flags);
2227 ios_lock(this);
2228 this->flags |= flags;
2229 ios_unlock(this);
2230 return prev;
2233 /* ?setf@ios@@QAEJJJ@Z */
2234 /* ?setf@ios@@QEAAJJJ@Z */
2235 DEFINE_THISCALL_WRAPPER(ios_setf_mask, 12)
2236 LONG __thiscall ios_setf_mask(ios *this, LONG flags, LONG mask)
2238 LONG prev = this->flags;
2240 TRACE("(%p %x %x)\n", this, flags, mask);
2242 ios_lock(this);
2243 this->flags = (this->flags & (~mask)) | (flags & mask);
2244 ios_unlock(this);
2245 return prev;
2248 /* ?setlock@ios@@QAAXXZ */
2249 /* ?setlock@ios@@QEAAXXZ */
2250 void __cdecl ios_setlock(ios *this)
2252 TRACE("(%p)\n", this);
2253 this->do_lock--;
2254 if (this->sb)
2255 streambuf_setlock(this->sb);
2258 /* ?tie@ios@@QAEPAVostream@@PAV2@@Z */
2259 /* ?tie@ios@@QEAAPEAVostream@@PEAV2@@Z */
2260 DEFINE_THISCALL_WRAPPER(ios_tie_set, 8)
2261 ostream* __thiscall ios_tie_set(ios *this, ostream *ostr)
2263 ostream *prev = this->tie;
2265 TRACE("(%p %p)\n", this, ostr);
2267 this->tie = ostr;
2268 return prev;
2271 /* ?tie@ios@@QBEPAVostream@@XZ */
2272 /* ?tie@ios@@QEBAPEAVostream@@XZ */
2273 DEFINE_THISCALL_WRAPPER(ios_tie_get, 4)
2274 ostream* __thiscall ios_tie_get(const ios *this)
2276 TRACE("(%p)\n", this);
2277 return this->tie;
2280 /* ?unlock@ios@@QAAXXZ */
2281 /* ?unlock@ios@@QEAAXXZ */
2282 void __cdecl ios_unlock(ios *this)
2284 TRACE("(%p)\n", this);
2285 if (this->do_lock < 0)
2286 LeaveCriticalSection(&this->lock);
2289 /* ?unlockbuf@ios@@QAAXXZ */
2290 /* ?unlockbuf@ios@@QEAAXXZ */
2291 void __cdecl ios_unlockbuf(ios *this)
2293 TRACE("(%p)\n", this);
2294 streambuf_unlock(this->sb);
2297 /* ?unlockc@ios@@KAXXZ */
2298 void __cdecl ios_unlockc(void)
2300 TRACE("()\n");
2301 LeaveCriticalSection(&ios_static_lock);
2304 /* ?unsetf@ios@@QAEJJ@Z */
2305 /* ?unsetf@ios@@QEAAJJ@Z */
2306 DEFINE_THISCALL_WRAPPER(ios_unsetf, 8)
2307 LONG __thiscall ios_unsetf(ios *this, LONG flags)
2309 LONG prev = this->flags;
2311 TRACE("(%p %x)\n", this, flags);
2313 ios_lock(this);
2314 this->flags &= ~flags;
2315 ios_unlock(this);
2316 return prev;
2319 /* ?width@ios@@QAEHH@Z */
2320 /* ?width@ios@@QEAAHH@Z */
2321 DEFINE_THISCALL_WRAPPER(ios_width_set, 8)
2322 int __thiscall ios_width_set(ios *this, int width)
2324 int prev = this->width;
2326 TRACE("(%p %d)\n", this, width);
2328 this->width = width;
2329 return prev;
2332 /* ?width@ios@@QBEHXZ */
2333 /* ?width@ios@@QEBAHXZ */
2334 DEFINE_THISCALL_WRAPPER(ios_width_get, 4)
2335 int __thiscall ios_width_get(const ios *this)
2337 TRACE("(%p)\n", this);
2338 return this->width;
2341 /* ?xalloc@ios@@SAHXZ */
2342 int __cdecl ios_xalloc(void)
2344 int ret;
2346 TRACE("()\n");
2348 ios_lockc();
2349 ret = (ios_curindex < STATEBUF_SIZE-1) ? ++ios_curindex : -1;
2350 ios_unlockc();
2351 return ret;
2354 static inline ios* ostream_get_ios(const ostream *this)
2356 return (ios*)((char*)this + this->vbtable[1]);
2359 static inline ios* ostream_to_ios(const ostream *this)
2361 return (ios*)((char*)this + ostream_vbtable[1]);
2364 static inline ostream* ios_to_ostream(const ios *base)
2366 return (ostream*)((char*)base - ostream_vbtable[1]);
2369 /* ??0ostream@@IAE@XZ */
2370 /* ??0ostream@@IEAA@XZ */
2371 DEFINE_THISCALL_WRAPPER(ostream_ctor, 8)
2372 ostream* __thiscall ostream_ctor(ostream *this, BOOL virt_init)
2374 ios *base;
2376 TRACE("(%p %d)\n", this, virt_init);
2378 if (virt_init) {
2379 this->vbtable = ostream_vbtable;
2380 base = ostream_get_ios(this);
2381 ios_ctor(base);
2382 } else
2383 base = ostream_get_ios(this);
2384 base->vtable = &MSVCP_ostream_vtable;
2385 this->unknown = 0;
2386 return this;
2389 /* ??0ostream@@QAE@PAVstreambuf@@@Z */
2390 /* ??0ostream@@QEAA@PEAVstreambuf@@@Z */
2391 DEFINE_THISCALL_WRAPPER(ostream_sb_ctor, 12)
2392 ostream* __thiscall ostream_sb_ctor(ostream *this, streambuf *sb, BOOL virt_init)
2394 TRACE("(%p %p %d)\n", this, sb, virt_init);
2395 ostream_ctor(this, virt_init);
2396 ios_init(ostream_get_ios(this), sb);
2397 return this;
2400 /* ??0ostream@@IAE@ABV0@@Z */
2401 /* ??0ostream@@IEAA@AEBV0@@Z */
2402 DEFINE_THISCALL_WRAPPER(ostream_copy_ctor, 12)
2403 ostream* __thiscall ostream_copy_ctor(ostream *this, const ostream *copy, BOOL virt_init)
2405 return ostream_sb_ctor(this, ostream_get_ios(copy)->sb, virt_init);
2408 /* ??1ostream@@UAE@XZ */
2409 /* ??1ostream@@UEAA@XZ */
2410 /* ??1ostream_withassign@@UAE@XZ */
2411 /* ??1ostream_withassign@@UEAA@XZ */
2412 /* ??1ostrstream@@UAE@XZ */
2413 /* ??1ostrstream@@UEAA@XZ */
2414 /* ??1ofstream@@UAE@XZ */
2415 /* ??1ofstream@@UEAA@XZ */
2416 DEFINE_THISCALL_WRAPPER(ostream_dtor, 4)
2417 void __thiscall ostream_dtor(ios *base)
2419 ostream *this = ios_to_ostream(base);
2421 TRACE("(%p)\n", this);
2424 /* ??4ostream@@IAEAAV0@PAVstreambuf@@@Z */
2425 /* ??4ostream@@IEAAAEAV0@PEAVstreambuf@@@Z */
2426 /* ??4ostream_withassign@@QAEAAVostream@@PAVstreambuf@@@Z */
2427 /* ??4ostream_withassign@@QEAAAEAVostream@@PEAVstreambuf@@@Z */
2428 DEFINE_THISCALL_WRAPPER(ostream_assign_sb, 8)
2429 ostream* __thiscall ostream_assign_sb(ostream *this, streambuf *sb)
2431 ios *base = ostream_get_ios(this);
2433 TRACE("(%p %p)\n", this, sb);
2435 ios_init(base, sb);
2436 base->state &= IOSTATE_badbit;
2437 base->delbuf = 0;
2438 base->tie = NULL;
2439 base->flags = 0;
2440 base->precision = 6;
2441 base->fill = ' ';
2442 base->width = 0;
2443 return this;
2446 /* ??4ostream@@IAEAAV0@ABV0@@Z */
2447 /* ??4ostream@@IEAAAEAV0@AEBV0@@Z */
2448 /* ??4ostream_withassign@@QAEAAV0@ABV0@@Z */
2449 /* ??4ostream_withassign@@QEAAAEAV0@AEBV0@@Z */
2450 /* ??4ostream_withassign@@QAEAAVostream@@ABV1@@Z */
2451 /* ??4ostream_withassign@@QEAAAEAVostream@@AEBV1@@Z */
2452 /* ??4ostrstream@@QAEAAV0@ABV0@@Z */
2453 /* ??4ostrstream@@QEAAAEAV0@AEBV0@@Z */
2454 /* ??4ofstream@@QAEAAV0@ABV0@@Z */
2455 /* ??4ofstream@@QEAAAEAV0@AEBV0@@Z */
2456 DEFINE_THISCALL_WRAPPER(ostream_assign, 8)
2457 ostream* __thiscall ostream_assign(ostream *this, const ostream *rhs)
2459 return ostream_assign_sb(this, ostream_get_ios(rhs)->sb);
2462 /* ??_Dostream@@QAEXXZ */
2463 /* ??_Dostream@@QEAAXXZ */
2464 /* ??_Dostream_withassign@@QAEXXZ */
2465 /* ??_Dostream_withassign@@QEAAXXZ */
2466 /* ??_Dostrstream@@QAEXXZ */
2467 /* ??_Dostrstream@@QEAAXXZ */
2468 /* ??_Dofstream@@QAEXXZ */
2469 /* ??_Dofstream@@QEAAXXZ */
2470 DEFINE_THISCALL_WRAPPER(ostream_vbase_dtor, 4)
2471 void __thiscall ostream_vbase_dtor(ostream *this)
2473 ios *base = ostream_to_ios(this);
2475 TRACE("(%p)\n", this);
2477 ostream_dtor(base);
2478 ios_dtor(base);
2481 /* ??_Eostream@@UAEPAXI@Z */
2482 /* ??_Eostream_withassign@@UAEPAXI@Z */
2483 /* ??_Eostrstream@@UAEPAXI@Z */
2484 /* ??_Eofstream@@UAEPAXI@Z */
2485 DEFINE_THISCALL_WRAPPER(ostream_vector_dtor, 8)
2486 ostream* __thiscall ostream_vector_dtor(ios *base, unsigned int flags)
2488 ostream *this = ios_to_ostream(base);
2490 TRACE("(%p %x)\n", this, flags);
2492 if (flags & 2) {
2493 /* we have an array, with the number of elements stored before the first object */
2494 INT_PTR i, *ptr = (INT_PTR *)this-1;
2496 for (i = *ptr-1; i >= 0; i--)
2497 ostream_vbase_dtor(this+i);
2498 MSVCRT_operator_delete(ptr);
2499 } else {
2500 ostream_vbase_dtor(this);
2501 if (flags & 1)
2502 MSVCRT_operator_delete(this);
2504 return this;
2507 /* ??_Gostream@@UAEPAXI@Z */
2508 /* ??_Gostream_withassign@@UAEPAXI@Z */
2509 /* ??_Gostrstream@@UAEPAXI@Z */
2510 /* ??_Gofstream@@UAEPAXI@Z */
2511 DEFINE_THISCALL_WRAPPER(ostream_scalar_dtor, 8)
2512 ostream* __thiscall ostream_scalar_dtor(ios *base, unsigned int flags)
2514 ostream *this = ios_to_ostream(base);
2516 TRACE("(%p %x)\n", this, flags);
2518 ostream_vbase_dtor(this);
2519 if (flags & 1) MSVCRT_operator_delete(this);
2520 return this;
2523 /* ?flush@ostream@@QAEAAV1@XZ */
2524 /* ?flush@ostream@@QEAAAEAV1@XZ */
2525 DEFINE_THISCALL_WRAPPER(ostream_flush, 4)
2526 ostream* __thiscall ostream_flush(ostream *this)
2528 ios *base = ostream_get_ios(this);
2530 TRACE("(%p)\n", this);
2532 ios_lockbuf(base);
2533 if (call_streambuf_sync(base->sb) == EOF)
2534 ios_clear(base, base->state | IOSTATE_failbit);
2535 ios_unlockbuf(base);
2536 return this;
2539 /* ?opfx@ostream@@QAEHXZ */
2540 /* ?opfx@ostream@@QEAAHXZ */
2541 DEFINE_THISCALL_WRAPPER(ostream_opfx, 4)
2542 int __thiscall ostream_opfx(ostream *this)
2544 ios *base = ostream_get_ios(this);
2546 TRACE("(%p)\n", this);
2548 if (!ios_good(base)) {
2549 ios_clear(base, base->state | IOSTATE_failbit);
2550 return 0;
2552 ios_lock(base);
2553 ios_lockbuf(base);
2554 if (base->tie)
2555 ostream_flush(base->tie);
2556 return 1;
2559 /* ?osfx@ostream@@QAEXXZ */
2560 /* ?osfx@ostream@@QEAAXXZ */
2561 DEFINE_THISCALL_WRAPPER(ostream_osfx, 4)
2562 void __thiscall ostream_osfx(ostream *this)
2564 ios *base = ostream_get_ios(this);
2566 TRACE("(%p)\n", this);
2568 ios_unlockbuf(base);
2569 ios_width_set(base, 0);
2570 if (base->flags & FLAGS_unitbuf)
2571 ostream_flush(this);
2572 if (base->flags & FLAGS_stdio) {
2573 fflush(stdout);
2574 fflush(stderr);
2576 ios_unlock(base);
2579 /* ?put@ostream@@QAEAAV1@C@Z */
2580 /* ?put@ostream@@QEAAAEAV1@C@Z */
2581 /* ?put@ostream@@QAEAAV1@D@Z */
2582 /* ?put@ostream@@QEAAAEAV1@D@Z */
2583 /* ?put@ostream@@QAEAAV1@E@Z */
2584 /* ?put@ostream@@QEAAAEAV1@E@Z */
2585 DEFINE_THISCALL_WRAPPER(ostream_put, 8)
2586 ostream* __thiscall ostream_put(ostream *this, char c)
2588 ios *base = ostream_get_ios(this);
2590 TRACE("(%p %c)\n", this, c);
2592 if (ostream_opfx(this)) {
2593 if (streambuf_sputc(base->sb, c) == EOF)
2594 base->state = IOSTATE_badbit | IOSTATE_failbit;
2595 ostream_osfx(this);
2597 return this;
2600 /* ?seekp@ostream@@QAEAAV1@J@Z */
2601 /* ?seekp@ostream@@QEAAAEAV1@J@Z */
2602 DEFINE_THISCALL_WRAPPER(ostream_seekp, 8)
2603 ostream* __thiscall ostream_seekp(ostream *this, streampos pos)
2605 ios *base = ostream_get_ios(this);
2607 TRACE("(%p %d)\n", this, pos);
2609 ios_lockbuf(base);
2610 if (streambuf_seekpos(base->sb, pos, OPENMODE_out) == EOF)
2611 ios_clear(base, base->state | IOSTATE_failbit);
2612 ios_unlockbuf(base);
2613 return this;
2616 /* ?seekp@ostream@@QAEAAV1@JW4seek_dir@ios@@@Z */
2617 /* ?seekp@ostream@@QEAAAEAV1@JW4seek_dir@ios@@@Z */
2618 DEFINE_THISCALL_WRAPPER(ostream_seekp_offset, 12)
2619 ostream* __thiscall ostream_seekp_offset(ostream *this, streamoff off, ios_seek_dir dir)
2621 ios *base = ostream_get_ios(this);
2623 TRACE("(%p %d %d)\n", this, off, dir);
2625 ios_lockbuf(base);
2626 if (call_streambuf_seekoff(base->sb, off, dir, OPENMODE_out) == EOF)
2627 ios_clear(base, base->state | IOSTATE_failbit);
2628 ios_unlockbuf(base);
2629 return this;
2632 /* ?tellp@ostream@@QAEJXZ */
2633 /* ?tellp@ostream@@QEAAJXZ */
2634 DEFINE_THISCALL_WRAPPER(ostream_tellp, 4)
2635 streampos __thiscall ostream_tellp(ostream *this)
2637 ios *base = ostream_get_ios(this);
2638 streampos pos;
2640 TRACE("(%p)\n", this);
2642 ios_lockbuf(base);
2643 if ((pos = call_streambuf_seekoff(base->sb, 0, SEEKDIR_cur, OPENMODE_out)) == EOF)
2644 ios_clear(base, base->state | IOSTATE_failbit);
2645 ios_unlockbuf(base);
2646 return pos;
2649 /* ?write@ostream@@QAEAAV1@PBCH@Z */
2650 /* ?write@ostream@@QEAAAEAV1@PEBCH@Z */
2651 /* ?write@ostream@@QAEAAV1@PBDH@Z */
2652 /* ?write@ostream@@QEAAAEAV1@PEBDH@Z */
2653 /* ?write@ostream@@QAEAAV1@PBEH@Z */
2654 /* ?write@ostream@@QEAAAEAV1@PEBEH@Z */
2655 DEFINE_THISCALL_WRAPPER(ostream_write, 12)
2656 ostream* __thiscall ostream_write(ostream *this, const char *str, int count)
2658 ios *base = ostream_get_ios(this);
2660 TRACE("(%p %p %d)\n", this, str, count);
2662 if (ostream_opfx(this)) {
2663 if (streambuf_sputn(base->sb, str, count) != count)
2664 base->state = IOSTATE_badbit | IOSTATE_failbit;
2665 ostream_osfx(this);
2667 return this;
2670 /* ?writepad@ostream@@AAEAAV1@PBD0@Z */
2671 /* ?writepad@ostream@@AEAAAEAV1@PEBD0@Z */
2672 DEFINE_THISCALL_WRAPPER(ostream_writepad, 12)
2673 ostream* __thiscall ostream_writepad(ostream *this, const char *str1, const char *str2)
2675 ios *base = ostream_get_ios(this);
2676 int len1 = strlen(str1), len2 = strlen(str2), i;
2678 TRACE("(%p %p %p)\n", this, str1, str2);
2680 /* left of the padding */
2681 if (base->flags & (FLAGS_left|FLAGS_internal)) {
2682 if (streambuf_sputn(base->sb, str1, len1) != len1)
2683 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2684 if (!(base->flags & FLAGS_internal))
2685 if (streambuf_sputn(base->sb, str2, len2) != len2)
2686 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2688 /* add padding to fill the width */
2689 for (i = len1 + len2; i < base->width; i++)
2690 if (streambuf_sputc(base->sb, base->fill) == EOF)
2691 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2692 /* right of the padding */
2693 if ((base->flags & (FLAGS_left|FLAGS_internal)) != FLAGS_left) {
2694 if (!(base->flags & (FLAGS_left|FLAGS_internal)))
2695 if (streambuf_sputn(base->sb, str1, len1) != len1)
2696 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2697 if (streambuf_sputn(base->sb, str2, len2) != len2)
2698 base->state |= IOSTATE_failbit | IOSTATE_badbit;
2700 return this;
2703 static ostream* ostream_internal_print_integer(ostream *ostr, int n, BOOL unsig, BOOL shrt)
2705 ios *base = ostream_get_ios(ostr);
2706 char prefix_str[3] = {0}, number_str[12], sprintf_fmt[4] = {'%','d',0};
2708 TRACE("(%p %d %d %d)\n", ostr, n, unsig, shrt);
2710 if (ostream_opfx(ostr)) {
2711 if (base->flags & FLAGS_hex) {
2712 sprintf_fmt[1] = (base->flags & FLAGS_uppercase) ? 'X' : 'x';
2713 if (base->flags & FLAGS_showbase) {
2714 prefix_str[0] = '0';
2715 prefix_str[1] = (base->flags & FLAGS_uppercase) ? 'X' : 'x';
2717 } else if (base->flags & FLAGS_oct) {
2718 sprintf_fmt[1] = 'o';
2719 if (base->flags & FLAGS_showbase)
2720 prefix_str[0] = '0';
2721 } else { /* FLAGS_dec */
2722 if (unsig)
2723 sprintf_fmt[1] = 'u';
2724 if ((base->flags & FLAGS_showpos) && n != 0 && (unsig || n > 0))
2725 prefix_str[0] = '+';
2728 if (shrt) {
2729 sprintf_fmt[2] = sprintf_fmt[1];
2730 sprintf_fmt[1] = 'h';
2733 if (sprintf(number_str, sprintf_fmt, n) > 0)
2734 ostream_writepad(ostr, prefix_str, number_str);
2735 else
2736 base->state |= IOSTATE_failbit;
2737 ostream_osfx(ostr);
2739 return ostr;
2742 static ostream* ostream_internal_print_float(ostream *ostr, double d, BOOL dbl)
2744 ios *base = ostream_get_ios(ostr);
2745 char prefix_str[2] = {0}, number_str[24], sprintf_fmt[6] = {'%','.','*','f',0};
2746 int prec, max_prec = dbl ? 15 : 6;
2747 int str_length = 1; /* null end char */
2749 TRACE("(%p %lf %d)\n", ostr, d, dbl);
2751 if (ostream_opfx(ostr)) {
2752 if ((base->flags & FLAGS_showpos) && d > 0) {
2753 prefix_str[0] = '+';
2754 str_length++; /* plus sign */
2756 if ((base->flags & (FLAGS_scientific|FLAGS_fixed)) == FLAGS_scientific)
2757 sprintf_fmt[3] = (base->flags & FLAGS_uppercase) ? 'E' : 'e';
2758 else if ((base->flags & (FLAGS_scientific|FLAGS_fixed)) != FLAGS_fixed)
2759 sprintf_fmt[3] = (base->flags & FLAGS_uppercase) ? 'G' : 'g';
2760 if (base->flags & FLAGS_showpoint) {
2761 sprintf_fmt[4] = sprintf_fmt[3];
2762 sprintf_fmt[3] = sprintf_fmt[2];
2763 sprintf_fmt[2] = sprintf_fmt[1];
2764 sprintf_fmt[1] = '#';
2767 prec = (base->precision >= 0 && base->precision <= max_prec) ? base->precision : max_prec;
2768 str_length += _scprintf(sprintf_fmt, prec, d); /* number representation */
2769 if (str_length > 24) {
2770 /* when the output length exceeds 24 characters, Windows prints an empty string with padding */
2771 ostream_writepad(ostr, "", "");
2772 } else {
2773 if (sprintf(number_str, sprintf_fmt, prec, d) > 0)
2774 ostream_writepad(ostr, prefix_str, number_str);
2775 else
2776 base->state |= IOSTATE_failbit;
2778 ostream_osfx(ostr);
2780 return ostr;
2783 /* ??6ostream@@QAEAAV0@C@Z */
2784 /* ??6ostream@@QEAAAEAV0@C@Z */
2785 /* ??6ostream@@QAEAAV0@D@Z */
2786 /* ??6ostream@@QEAAAEAV0@D@Z */
2787 /* ??6ostream@@QAEAAV0@E@Z */
2788 /* ??6ostream@@QEAAAEAV0@E@Z */
2789 DEFINE_THISCALL_WRAPPER(ostream_print_char, 8)
2790 ostream* __thiscall ostream_print_char(ostream *this, char c)
2792 const char c_str[2] = {c, 0};
2794 TRACE("(%p %c)\n", this, c);
2796 if (ostream_opfx(this)) {
2797 ostream_writepad(this, "", c_str);
2798 ostream_osfx(this);
2800 return this;
2803 /* ??6ostream@@QAEAAV0@PBC@Z */
2804 /* ??6ostream@@QEAAAEAV0@PEBC@Z */
2805 /* ??6ostream@@QAEAAV0@PBD@Z */
2806 /* ??6ostream@@QEAAAEAV0@PEBD@Z */
2807 /* ??6ostream@@QAEAAV0@PBE@Z */
2808 /* ??6ostream@@QEAAAEAV0@PEBE@Z */
2809 DEFINE_THISCALL_WRAPPER(ostream_print_str, 8)
2810 ostream* __thiscall ostream_print_str(ostream *this, const char *str)
2812 TRACE("(%p %s)\n", this, str);
2813 if (ostream_opfx(this)) {
2814 ostream_writepad(this, "", str);
2815 ostream_osfx(this);
2817 return this;
2820 /* ??6ostream@@QAEAAV0@F@Z */
2821 /* ??6ostream@@QEAAAEAV0@F@Z */
2822 DEFINE_THISCALL_WRAPPER(ostream_print_short, 8)
2823 ostream* __thiscall ostream_print_short(ostream *this, short n)
2825 return ostream_internal_print_integer(this, n, FALSE, TRUE);
2828 /* ??6ostream@@QAEAAV0@G@Z */
2829 /* ??6ostream@@QEAAAEAV0@G@Z */
2830 DEFINE_THISCALL_WRAPPER(ostream_print_unsigned_short, 8)
2831 ostream* __thiscall ostream_print_unsigned_short(ostream *this, unsigned short n)
2833 return ostream_internal_print_integer(this, n, TRUE, TRUE);
2836 /* ??6ostream@@QAEAAV0@H@Z */
2837 /* ??6ostream@@QEAAAEAV0@H@Z */
2838 /* ??6ostream@@QAEAAV0@J@Z */
2839 /* ??6ostream@@QEAAAEAV0@J@Z */
2840 DEFINE_THISCALL_WRAPPER(ostream_print_int, 8)
2841 ostream* __thiscall ostream_print_int(ostream *this, int n)
2843 return ostream_internal_print_integer(this, n, FALSE, FALSE);
2846 /* ??6ostream@@QAEAAV0@I@Z */
2847 /* ??6ostream@@QEAAAEAV0@I@Z */
2848 /* ??6ostream@@QAEAAV0@K@Z */
2849 /* ??6ostream@@QEAAAEAV0@K@Z */
2850 DEFINE_THISCALL_WRAPPER(ostream_print_unsigned_int, 8)
2851 ostream* __thiscall ostream_print_unsigned_int(ostream *this, unsigned int n)
2853 return ostream_internal_print_integer(this, n, TRUE, FALSE);
2856 /* ??6ostream@@QAEAAV0@M@Z */
2857 /* ??6ostream@@QEAAAEAV0@M@Z */
2858 DEFINE_THISCALL_WRAPPER(ostream_print_float, 8)
2859 ostream* __thiscall ostream_print_float(ostream *this, float f)
2861 return ostream_internal_print_float(this, f, FALSE);
2864 /* ??6ostream@@QAEAAV0@N@Z */
2865 /* ??6ostream@@QEAAAEAV0@N@Z */
2866 /* ??6ostream@@QAEAAV0@O@Z */
2867 /* ??6ostream@@QEAAAEAV0@O@Z */
2868 DEFINE_THISCALL_WRAPPER(ostream_print_double, 12)
2869 ostream* __thiscall ostream_print_double(ostream *this, double d)
2871 return ostream_internal_print_float(this, d, TRUE);
2874 /* ??6ostream@@QAEAAV0@PBX@Z */
2875 /* ??6ostream@@QEAAAEAV0@PEBX@Z */
2876 DEFINE_THISCALL_WRAPPER(ostream_print_ptr, 8)
2877 ostream* __thiscall ostream_print_ptr(ostream *this, const void *ptr)
2879 ios *base = ostream_get_ios(this);
2880 char prefix_str[3] = {'0','x',0}, pointer_str[17];
2882 TRACE("(%p %p)\n", this, ptr);
2884 if (ostream_opfx(this)) {
2885 if (ptr && base->flags & FLAGS_uppercase)
2886 prefix_str[1] = 'X';
2888 if (sprintf(pointer_str, "%p", ptr) > 0)
2889 ostream_writepad(this, prefix_str, pointer_str);
2890 else
2891 base->state |= IOSTATE_failbit;
2892 ostream_osfx(this);
2894 return this;
2897 /* ??6ostream@@QAEAAV0@PAVstreambuf@@@Z */
2898 /* ??6ostream@@QEAAAEAV0@PEAVstreambuf@@@Z */
2899 DEFINE_THISCALL_WRAPPER(ostream_print_streambuf, 8)
2900 ostream* __thiscall ostream_print_streambuf(ostream *this, streambuf *sb)
2902 ios *base = ostream_get_ios(this);
2903 int c;
2905 TRACE("(%p %p)\n", this, sb);
2907 if (ostream_opfx(this)) {
2908 while ((c = streambuf_sbumpc(sb)) != EOF) {
2909 if (streambuf_sputc(base->sb, c) == EOF) {
2910 base->state |= IOSTATE_failbit;
2911 break;
2914 ostream_osfx(this);
2916 return this;
2919 /* ??6ostream@@QAEAAV0@P6AAAV0@AAV0@@Z@Z */
2920 /* ??6ostream@@QEAAAEAV0@P6AAEAV0@AEAV0@@Z@Z */
2921 DEFINE_THISCALL_WRAPPER(ostream_print_manip, 8)
2922 ostream* __thiscall ostream_print_manip(ostream *this, ostream* (__cdecl *func)(ostream*))
2924 TRACE("(%p %p)\n", this, func);
2925 return func(this);
2928 /* ??6ostream@@QAEAAV0@P6AAAVios@@AAV1@@Z@Z */
2929 /* ??6ostream@@QEAAAEAV0@P6AAEAVios@@AEAV1@@Z@Z */
2930 DEFINE_THISCALL_WRAPPER(ostream_print_ios_manip, 8)
2931 ostream* __thiscall ostream_print_ios_manip(ostream *this, ios* (__cdecl *func)(ios*))
2933 TRACE("(%p %p)\n", this, func);
2934 func(ostream_get_ios(this));
2935 return this;
2938 /* ?endl@@YAAAVostream@@AAV1@@Z */
2939 /* ?endl@@YAAEAVostream@@AEAV1@@Z */
2940 ostream* __cdecl ostream_endl(ostream *this)
2942 TRACE("(%p)\n", this);
2943 ostream_put(this, '\n');
2944 return ostream_flush(this);
2947 /* ?ends@@YAAAVostream@@AAV1@@Z */
2948 /* ?ends@@YAAEAVostream@@AEAV1@@Z */
2949 ostream* __cdecl ostream_ends(ostream *this)
2951 TRACE("(%p)\n", this);
2952 return ostream_put(this, 0);
2955 /* ?flush@@YAAAVostream@@AAV1@@Z */
2956 /* ?flush@@YAAEAVostream@@AEAV1@@Z */
2957 ostream* __cdecl ostream_flush_manip(ostream *this)
2959 TRACE("(%p)\n", this);
2960 return ostream_flush(this);
2963 /* ??0ostream_withassign@@QAE@ABV0@@Z */
2964 /* ??0ostream_withassign@@QEAA@AEBV0@@Z */
2965 DEFINE_THISCALL_WRAPPER(ostream_withassign_copy_ctor, 12)
2966 ostream* __thiscall ostream_withassign_copy_ctor(ostream *this, const ostream *copy, BOOL virt_init)
2968 ios *base, *base_copy;
2970 TRACE("(%p %p %d)\n", this, copy, virt_init);
2972 base_copy = ostream_get_ios(copy);
2973 if (virt_init) {
2974 this->vbtable = ostream_vbtable;
2975 base = ostream_get_ios(this);
2976 ios_copy_ctor(base, base_copy);
2977 } else
2978 base = ostream_get_ios(this);
2979 ios_init(base, base_copy->sb);
2980 base->vtable = &MSVCP_ostream_withassign_vtable;
2981 this->unknown = 0;
2982 return this;
2985 /* ??0ostream_withassign@@QAE@PAVstreambuf@@@Z */
2986 /* ??0ostream_withassign@@QEAA@PEAVstreambuf@@@Z */
2987 DEFINE_THISCALL_WRAPPER(ostream_withassign_sb_ctor, 12)
2988 ostream* __thiscall ostream_withassign_sb_ctor(ostream *this, streambuf *sb, BOOL virt_init)
2990 ios *base;
2992 TRACE("(%p %p %d)\n", this, sb, virt_init);
2994 ostream_sb_ctor(this, sb, virt_init);
2995 base = ostream_get_ios(this);
2996 base->vtable = &MSVCP_ostream_withassign_vtable;
2997 return this;
3000 /* ??0ostream_withassign@@QAE@XZ */
3001 /* ??0ostream_withassign@@QEAA@XZ */
3002 DEFINE_THISCALL_WRAPPER(ostream_withassign_ctor, 8)
3003 ostream* __thiscall ostream_withassign_ctor(ostream *this, BOOL virt_init)
3005 ios *base;
3007 TRACE("(%p %d)\n", this, virt_init);
3009 ostream_ctor(this, virt_init);
3010 base = ostream_get_ios(this);
3011 base->vtable = &MSVCP_ostream_withassign_vtable;
3012 return this;
3015 static ostream* ostrstream_internal_sb_ctor(ostream *this, strstreambuf *ssb, BOOL virt_init)
3017 ios *base;
3019 if (ssb)
3020 ostream_sb_ctor(this, &ssb->base, virt_init);
3021 else
3022 ostream_ctor(this, virt_init);
3023 base = ostream_get_ios(this);
3024 base->vtable = &MSVCP_ostrstream_vtable;
3025 base->delbuf = 1;
3026 return this;
3029 /* ??0ostrstream@@QAE@ABV0@@Z */
3030 /* ??0ostrstream@@QEAA@AEBV0@@Z */
3031 DEFINE_THISCALL_WRAPPER(ostrstream_copy_ctor, 12)
3032 ostream* __thiscall ostrstream_copy_ctor(ostream *this, const ostream *copy, BOOL virt_init)
3034 TRACE("(%p %p %d)\n", this, copy, virt_init);
3035 ostream_withassign_copy_ctor(this, copy, virt_init);
3036 ostream_get_ios(this)->vtable = &MSVCP_ostrstream_vtable;
3037 return this;
3040 /* ??0ostrstream@@QAE@PADHH@Z */
3041 /* ??0ostrstream@@QEAA@PEADHH@Z */
3042 DEFINE_THISCALL_WRAPPER(ostrstream_buffer_ctor, 20)
3043 ostream* __thiscall ostrstream_buffer_ctor(ostream *this, char *buffer, int length, int mode, BOOL virt_init)
3045 strstreambuf *ssb = MSVCRT_operator_new(sizeof(strstreambuf));
3047 TRACE("(%p %p %d %d %d)\n", this, buffer, length, mode, virt_init);
3049 if (!ssb) {
3050 FIXME("out of memory\n");
3051 return NULL;
3054 strstreambuf_buffer_ctor(ssb, buffer, length, buffer);
3055 if (mode & (OPENMODE_app|OPENMODE_ate))
3056 ssb->base.pptr = buffer + strlen(buffer);
3058 return ostrstream_internal_sb_ctor(this, ssb, virt_init);
3061 /* ??0ostrstream@@QAE@XZ */
3062 /* ??0ostrstream@@QEAA@XZ */
3063 DEFINE_THISCALL_WRAPPER(ostrstream_ctor, 8)
3064 ostream* __thiscall ostrstream_ctor(ostream *this, BOOL virt_init)
3066 strstreambuf *ssb = MSVCRT_operator_new(sizeof(strstreambuf));
3068 TRACE("(%p %d)\n", this, virt_init);
3070 if (!ssb) {
3071 FIXME("out of memory\n");
3072 return NULL;
3075 strstreambuf_ctor(ssb);
3077 return ostrstream_internal_sb_ctor(this, ssb, virt_init);
3080 /* ?pcount@ostrstream@@QBEHXZ */
3081 /* ?pcount@ostrstream@@QEBAHXZ */
3082 DEFINE_THISCALL_WRAPPER(ostrstream_pcount, 4)
3083 int __thiscall ostrstream_pcount(const ostream *this)
3085 return streambuf_out_waiting(ostream_get_ios(this)->sb);
3088 /* ?rdbuf@ostrstream@@QBEPAVstrstreambuf@@XZ */
3089 /* ?rdbuf@ostrstream@@QEBAPEAVstrstreambuf@@XZ */
3090 DEFINE_THISCALL_WRAPPER(ostrstream_rdbuf, 4)
3091 strstreambuf* __thiscall ostrstream_rdbuf(const ostream *this)
3093 return (strstreambuf*) ostream_get_ios(this)->sb;
3096 /* ?str@ostrstream@@QAEPADXZ */
3097 /* ?str@ostrstream@@QEAAPEADXZ */
3098 DEFINE_THISCALL_WRAPPER(ostrstream_str, 4)
3099 char* __thiscall ostrstream_str(ostream *this)
3101 return strstreambuf_str(ostrstream_rdbuf(this));
3104 /* ??0ofstream@@QAE@ABV0@@Z */
3105 /* ??0ofstream@@QEAA@AEBV0@@Z */
3106 DEFINE_THISCALL_WRAPPER(ofstream_copy_ctor, 12)
3107 ostream* __thiscall ofstream_copy_ctor(ostream *this, const ostream *copy, BOOL virt_init)
3109 TRACE("(%p %p %d)\n", this, copy, virt_init);
3110 ostream_withassign_copy_ctor(this, copy, virt_init);
3111 ostream_get_ios(this)->vtable = &MSVCP_ofstream_vtable;
3112 return this;
3115 /* ??0ofstream@@QAE@HPADH@Z */
3116 /* ??0ofstream@@QEAA@HPEADH@Z */
3117 DEFINE_THISCALL_WRAPPER(ofstream_buffer_ctor, 20)
3118 ostream* __thiscall ofstream_buffer_ctor(ostream *this, filedesc fd, char *buffer, int length, BOOL virt_init)
3120 ios *base;
3121 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
3123 TRACE("(%p %d %p %d %d)\n", this, fd, buffer, length, virt_init);
3125 if (!fb) {
3126 FIXME("out of memory\n");
3127 return NULL;
3130 filebuf_fd_reserve_ctor(fb, fd, buffer, length);
3131 ostream_sb_ctor(this, &fb->base, virt_init);
3133 base = ostream_get_ios(this);
3134 base->vtable = &MSVCP_ofstream_vtable;
3135 base->delbuf = 1;
3137 return this;
3140 /* ??0ofstream@@QAE@H@Z */
3141 /* ??0ofstream@@QEAA@H@Z */
3142 DEFINE_THISCALL_WRAPPER(ofstream_fd_ctor, 12)
3143 ostream* __thiscall ofstream_fd_ctor(ostream *this, filedesc fd, BOOL virt_init)
3145 ios *base;
3146 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
3148 TRACE("(%p %d %d)\n", this, fd, virt_init);
3150 if (!fb) {
3151 FIXME("out of memory\n");
3152 return NULL;
3155 filebuf_fd_ctor(fb, fd);
3156 ostream_sb_ctor(this, &fb->base, virt_init);
3158 base = ostream_get_ios(this);
3159 base->vtable = &MSVCP_ofstream_vtable;
3160 base->delbuf = 1;
3162 return this;
3165 /* ??0ofstream@@QAE@PBDHH@Z */
3166 /* ??0ofstream@@QEAA@PEBDHH@Z */
3167 DEFINE_THISCALL_WRAPPER(ofstream_open_ctor, 20)
3168 ostream* __thiscall ofstream_open_ctor(ostream *this, const char *name, int mode, int protection, BOOL virt_init)
3170 ios *base;
3171 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
3173 TRACE("(%p %s %d %d %d)\n", this, name, mode, protection, virt_init);
3175 if (!fb) {
3176 FIXME("out of memory\n");
3177 return NULL;
3180 filebuf_ctor(fb);
3181 ostream_sb_ctor(this, &fb->base, virt_init);
3183 base = ostream_get_ios(this);
3184 base->vtable = &MSVCP_ofstream_vtable;
3185 base->delbuf = 1;
3187 if (filebuf_open(fb, name, mode|OPENMODE_out, protection) == NULL)
3188 base->state |= IOSTATE_failbit;
3189 return this;
3192 /* ??0ofstream@@QAE@XZ */
3193 /* ??0ofstream@@QEAA@XZ */
3194 DEFINE_THISCALL_WRAPPER(ofstream_ctor, 8)
3195 ostream* __thiscall ofstream_ctor(ostream *this, BOOL virt_init)
3197 return ofstream_fd_ctor(this, -1, virt_init);
3200 /* ?rdbuf@ofstream@@QBEPAVfilebuf@@XZ */
3201 /* ?rdbuf@ofstream@@QEBAPEAVfilebuf@@XZ */
3202 DEFINE_THISCALL_WRAPPER(ofstream_rdbuf, 4)
3203 filebuf* __thiscall ofstream_rdbuf(const ostream *this)
3205 TRACE("(%p)\n", this);
3206 return (filebuf*) ostream_get_ios(this)->sb;
3209 /* ?fd@ofstream@@QBEHXZ */
3210 /* ?fd@ofstream@@QEBAHXZ */
3211 DEFINE_THISCALL_WRAPPER(ofstream_fd, 4)
3212 filedesc __thiscall ofstream_fd(ostream *this)
3214 TRACE("(%p)\n", this);
3215 return filebuf_fd(ofstream_rdbuf(this));
3218 /* ?attach@ofstream@@QAEXH@Z */
3219 /* ?attach@ofstream@@QEAAXH@Z */
3220 DEFINE_THISCALL_WRAPPER(ofstream_attach, 8)
3221 void __thiscall ofstream_attach(ostream *this, filedesc fd)
3223 ios *base = ostream_get_ios(this);
3224 TRACE("(%p %d)\n", this, fd);
3225 if (filebuf_attach(ofstream_rdbuf(this), fd) == NULL)
3226 ios_clear(base, base->state | IOSTATE_failbit);
3229 /* ?close@ofstream@@QAEXXZ */
3230 /* ?close@ofstream@@QEAAXXZ */
3231 DEFINE_THISCALL_WRAPPER(ofstream_close, 4)
3232 void __thiscall ofstream_close(ostream *this)
3234 ios *base = ostream_get_ios(this);
3235 TRACE("(%p)\n", this);
3236 if (filebuf_close(ofstream_rdbuf(this)) == NULL)
3237 ios_clear(base, base->state | IOSTATE_failbit);
3238 else
3239 ios_clear(base, IOSTATE_goodbit);
3242 /* ?is_open@ofstream@@QBEHXZ */
3243 /* ?is_open@ofstream@@QEBAHXZ */
3244 DEFINE_THISCALL_WRAPPER(ofstream_is_open, 4)
3245 int __thiscall ofstream_is_open(const ostream *this)
3247 TRACE("(%p)\n", this);
3248 return filebuf_is_open(ofstream_rdbuf(this));
3251 /* ?open@ofstream@@QAEXPBDHH@Z */
3252 /* ?open@ofstream@@QEAAXPEBDHH@Z */
3253 DEFINE_THISCALL_WRAPPER(ofstream_open, 16)
3254 void __thiscall ofstream_open(ostream *this, const char *name, ios_open_mode mode, int protection)
3256 ios *base = ostream_get_ios(this);
3257 TRACE("(%p %s %d %d)\n", this, name, mode, protection);
3258 if (filebuf_open(ofstream_rdbuf(this), name, mode|OPENMODE_out, protection) == NULL)
3259 ios_clear(base, base->state | IOSTATE_failbit);
3262 /* ?setbuf@ofstream@@QAEPAVstreambuf@@PADH@Z */
3263 /* ?setbuf@ofstream@@QEAAPEAVstreambuf@@PEADH@Z */
3264 DEFINE_THISCALL_WRAPPER(ofstream_setbuf, 12)
3265 streambuf* __thiscall ofstream_setbuf(ostream *this, char *buffer, int length)
3267 ios *base = ostream_get_ios(this);
3268 filebuf* fb = ofstream_rdbuf(this);
3270 TRACE("(%p %p %d)\n", this, buffer, length);
3272 if (filebuf_is_open(fb)) {
3273 ios_clear(base, base->state | IOSTATE_failbit);
3274 return NULL;
3277 return filebuf_setbuf(fb, buffer, length);
3280 /* ?setmode@ofstream@@QAEHH@Z */
3281 /* ?setmode@ofstream@@QEAAHH@Z */
3282 DEFINE_THISCALL_WRAPPER(ofstream_setmode, 8)
3283 int __thiscall ofstream_setmode(ostream *this, int mode)
3285 TRACE("(%p %d)\n", this, mode);
3286 return filebuf_setmode(ofstream_rdbuf(this), mode);
3289 static inline ios* istream_get_ios(const istream *this)
3291 return (ios*)((char*)this + this->vbtable[1]);
3294 static inline ios* istream_to_ios(const istream *this)
3296 return (ios*)((char*)this + istream_vbtable[1]);
3299 static inline istream* ios_to_istream(const ios *base)
3301 return (istream*)((char*)base - istream_vbtable[1]);
3304 /* ??0istream@@IAE@XZ */
3305 /* ??0istream@@IEAA@XZ */
3306 DEFINE_THISCALL_WRAPPER(istream_ctor, 8)
3307 istream* __thiscall istream_ctor(istream *this, BOOL virt_init)
3309 ios *base;
3311 TRACE("(%p %d)\n", this, virt_init);
3313 if (virt_init) {
3314 this->vbtable = istream_vbtable;
3315 base = istream_get_ios(this);
3316 ios_ctor(base);
3317 } else
3318 base = istream_get_ios(this);
3319 base->vtable = &MSVCP_istream_vtable;
3320 base->flags |= FLAGS_skipws;
3321 this->extract_delim = 0;
3322 this->count = 0;
3323 return this;
3326 /* ??0istream@@QAE@PAVstreambuf@@@Z */
3327 /* ??0istream@@QEAA@PEAVstreambuf@@@Z */
3328 DEFINE_THISCALL_WRAPPER(istream_sb_ctor, 12)
3329 istream* __thiscall istream_sb_ctor(istream *this, streambuf *sb, BOOL virt_init)
3331 TRACE("(%p %p %d)\n", this, sb, virt_init);
3332 istream_ctor(this, virt_init);
3333 ios_init(istream_get_ios(this), sb);
3334 return this;
3337 /* ??0istream@@IAE@ABV0@@Z */
3338 /* ??0istream@@IEAA@AEBV0@@Z */
3339 DEFINE_THISCALL_WRAPPER(istream_copy_ctor, 12)
3340 istream* __thiscall istream_copy_ctor(istream *this, const istream *copy, BOOL virt_init)
3342 return istream_sb_ctor(this, istream_get_ios(copy)->sb, virt_init);
3345 /* ??1istream@@UAE@XZ */
3346 /* ??1istream@@UEAA@XZ */
3347 /* ??1istream_withassign@@UAE@XZ */
3348 /* ??1istream_withassign@@UEAA@XZ */
3349 /* ??1istrstream@@UAE@XZ */
3350 /* ??1istrstream@@UEAA@XZ */
3351 /* ??1ifstream@@UAE@XZ */
3352 /* ??1ifstream@@UEAA@XZ */
3353 DEFINE_THISCALL_WRAPPER(istream_dtor, 4)
3354 void __thiscall istream_dtor(ios *base)
3356 istream *this = ios_to_istream(base);
3358 TRACE("(%p)\n", this);
3361 /* ??4istream@@IAEAAV0@PAVstreambuf@@@Z */
3362 /* ??4istream@@IEAAAEAV0@PEAVstreambuf@@@Z */
3363 /* ??4istream_withassign@@QAEAAVistream@@PAVstreambuf@@@Z */
3364 /* ??4istream_withassign@@QEAAAEAVistream@@PEAVstreambuf@@@Z */
3365 DEFINE_THISCALL_WRAPPER(istream_assign_sb, 8)
3366 istream* __thiscall istream_assign_sb(istream *this, streambuf *sb)
3368 ios *base = istream_get_ios(this);
3370 TRACE("(%p %p)\n", this, sb);
3372 ios_init(base, sb);
3373 base->state &= IOSTATE_badbit;
3374 base->delbuf = 0;
3375 base->tie = NULL;
3376 base->flags = FLAGS_skipws;
3377 base->precision = 6;
3378 base->fill = ' ';
3379 base->width = 0;
3380 this->count = 0;
3381 return this;
3384 /* ??4istream@@IAEAAV0@ABV0@@Z */
3385 /* ??4istream@@IEAAAEAV0@AEBV0@@Z */
3386 /* ??4istream_withassign@@QAEAAV0@ABV0@@Z */
3387 /* ??4istream_withassign@@QEAAAEAV0@AEBV0@@Z */
3388 /* ??4istream_withassign@@QAEAAVistream@@ABV1@@Z */
3389 /* ??4istream_withassign@@QEAAAEAVistream@@AEBV1@@Z */
3390 /* ??4istrstream@@QAEAAV0@ABV0@@Z */
3391 /* ??4istrstream@@QEAAAEAV0@AEBV0@@Z */
3392 /* ??4ifstream@@QAEAAV0@ABV0@@Z */
3393 /* ??4ifstream@@QEAAAEAV0@AEBV0@@Z */
3394 DEFINE_THISCALL_WRAPPER(istream_assign, 8)
3395 istream* __thiscall istream_assign(istream *this, const istream *rhs)
3397 return istream_assign_sb(this, istream_get_ios(rhs)->sb);
3400 /* ??_Distream@@QAEXXZ */
3401 /* ??_Distream@@QEAAXXZ */
3402 /* ??_Distream_withassign@@QAEXXZ */
3403 /* ??_Distream_withassign@@QEAAXXZ */
3404 /* ??_Distrstream@@QAEXXZ */
3405 /* ??_Distrstream@@QEAAXXZ */
3406 /* ??_Difstream@@QAEXXZ */
3407 /* ??_Difstream@@QEAAXXZ */
3408 DEFINE_THISCALL_WRAPPER(istream_vbase_dtor, 4)
3409 void __thiscall istream_vbase_dtor(istream *this)
3411 ios *base = istream_to_ios(this);
3413 TRACE("(%p)\n", this);
3415 istream_dtor(base);
3416 ios_dtor(base);
3419 /* ??_Eistream@@UAEPAXI@Z */
3420 /* ??_Eistream_withassign@@UAEPAXI@Z */
3421 /* ??_Eistrstream@@UAEPAXI@Z */
3422 /* ??_Eifstream@@UAEPAXI@Z */
3423 DEFINE_THISCALL_WRAPPER(istream_vector_dtor, 8)
3424 istream* __thiscall istream_vector_dtor(ios *base, unsigned int flags)
3426 istream *this = ios_to_istream(base);
3428 TRACE("(%p %x)\n", this, flags);
3430 if (flags & 2) {
3431 /* we have an array, with the number of elements stored before the first object */
3432 INT_PTR i, *ptr = (INT_PTR *)this-1;
3434 for (i = *ptr-1; i >= 0; i--)
3435 istream_vbase_dtor(this+i);
3436 MSVCRT_operator_delete(ptr);
3437 } else {
3438 istream_vbase_dtor(this);
3439 if (flags & 1)
3440 MSVCRT_operator_delete(this);
3442 return this;
3445 /* ??_Gistream@@UAEPAXI@Z */
3446 /* ??_Gistream_withassign@@UAEPAXI@Z */
3447 /* ??_Gistrstream@@UAEPAXI@Z */
3448 /* ??_Gifstream@@UAEPAXI@Z */
3449 DEFINE_THISCALL_WRAPPER(istream_scalar_dtor, 8)
3450 istream* __thiscall istream_scalar_dtor(ios *base, unsigned int flags)
3452 istream *this = ios_to_istream(base);
3454 TRACE("(%p %x)\n", this, flags);
3456 istream_vbase_dtor(this);
3457 if (flags & 1) MSVCRT_operator_delete(this);
3458 return this;
3461 /* ?eatwhite@istream@@QAEXXZ */
3462 /* ?eatwhite@istream@@QEAAXXZ */
3463 DEFINE_THISCALL_WRAPPER(istream_eatwhite, 4)
3464 void __thiscall istream_eatwhite(istream *this)
3466 ios *base = istream_get_ios(this);
3467 int c;
3469 TRACE("(%p)\n", this);
3471 ios_lockbuf(base);
3472 for (c = streambuf_sgetc(base->sb); isspace(c); c = streambuf_snextc(base->sb));
3473 ios_unlockbuf(base);
3474 if (c == EOF)
3475 ios_clear(base, base->state | IOSTATE_eofbit);
3478 /* ?gcount@istream@@QBEHXZ */
3479 /* ?gcount@istream@@QEBAHXZ */
3480 DEFINE_THISCALL_WRAPPER(istream_gcount, 4)
3481 int __thiscall istream_gcount(const istream *this)
3483 TRACE("(%p)\n", this);
3484 return this->count;
3487 /* ?ipfx@istream@@QAEHH@Z */
3488 /* ?ipfx@istream@@QEAAHH@Z */
3489 DEFINE_THISCALL_WRAPPER(istream_ipfx, 8)
3490 int __thiscall istream_ipfx(istream *this, int need)
3492 ios *base = istream_get_ios(this);
3494 TRACE("(%p %d)\n", this, need);
3496 if (need)
3497 this->count = 0;
3498 if (!ios_good(base)) {
3499 ios_clear(base, base->state | IOSTATE_failbit);
3500 return 0;
3502 ios_lock(base);
3503 ios_lockbuf(base);
3504 if (base->tie && (!need || streambuf_in_avail(base->sb) < need))
3505 ostream_flush(base->tie);
3506 if ((base->flags & FLAGS_skipws) && !need) {
3507 istream_eatwhite(this);
3508 if (base->state & IOSTATE_eofbit) {
3509 base->state |= IOSTATE_failbit;
3510 ios_unlockbuf(base);
3511 ios_unlock(base);
3512 return 0;
3515 return 1;
3518 /* ?isfx@istream@@QAEXXZ */
3519 /* ?isfx@istream@@QEAAXXZ */
3520 DEFINE_THISCALL_WRAPPER(istream_isfx, 4)
3521 void __thiscall istream_isfx(istream *this)
3523 ios *base = istream_get_ios(this);
3525 TRACE("(%p)\n", this);
3527 ios_unlockbuf(base);
3528 ios_unlock(base);
3531 /* ?get@istream@@IAEAAV1@PADHH@Z */
3532 /* ?get@istream@@IEAAAEAV1@PEADHH@Z */
3533 DEFINE_THISCALL_WRAPPER(istream_get_str_delim, 16)
3534 istream* __thiscall istream_get_str_delim(istream *this, char *str, int count, int delim)
3536 ios *base = istream_get_ios(this);
3537 int ch, i = 0;
3539 TRACE("(%p %p %d %d)\n", this, str, count, delim);
3541 if (istream_ipfx(this, 1)) {
3542 while (i < count - 1) {
3543 if ((ch = streambuf_sgetc(base->sb)) == EOF) {
3544 base->state |= IOSTATE_eofbit;
3545 if (!i) /* tried to read, but not a single character was obtained */
3546 base->state |= IOSTATE_failbit;
3547 break;
3549 if (ch == delim) {
3550 if (this->extract_delim) { /* discard the delimiter */
3551 streambuf_stossc(base->sb);
3552 this->count++;
3554 break;
3556 if (str)
3557 str[i] = ch;
3558 streambuf_stossc(base->sb);
3559 i++;
3561 this->count += i;
3562 istream_isfx(this);
3564 if (str && count) /* append a null terminator, unless a string of 0 characters was requested */
3565 str[i] = 0;
3566 this->extract_delim = 0;
3567 return this;
3570 /* ?get@istream@@QAEAAV1@PACHD@Z */
3571 /* ?get@istream@@QEAAAEAV1@PEACHD@Z */
3572 /* ?get@istream@@QAEAAV1@PADHD@Z */
3573 /* ?get@istream@@QEAAAEAV1@PEADHD@Z */
3574 /* ?get@istream@@QAEAAV1@PAEHD@Z */
3575 /* ?get@istream@@QEAAAEAV1@PEAEHD@Z */
3576 DEFINE_THISCALL_WRAPPER(istream_get_str, 16)
3577 istream* __thiscall istream_get_str(istream *this, char *str, int count, char delim)
3579 return istream_get_str_delim(this, str, count, (unsigned char) delim);
3582 static int istream_internal_get_char(istream *this, char *ch)
3584 ios *base = istream_get_ios(this);
3585 int ret = EOF;
3587 TRACE("(%p %p)\n", this, ch);
3589 if (istream_ipfx(this, 1)) {
3590 if ((ret = streambuf_sbumpc(base->sb)) != EOF) {
3591 this->count = 1;
3592 } else {
3593 base->state |= IOSTATE_eofbit;
3594 if (ch)
3595 base->state |= IOSTATE_failbit;
3597 if (ch)
3598 *ch = ret;
3599 istream_isfx(this);
3601 return ret;
3604 /* ?get@istream@@QAEAAV1@AAC@Z */
3605 /* ?get@istream@@QEAAAEAV1@AEAC@Z */
3606 /* ?get@istream@@QAEAAV1@AAD@Z */
3607 /* ?get@istream@@QEAAAEAV1@AEAD@Z */
3608 /* ?get@istream@@QAEAAV1@AAE@Z */
3609 /* ?get@istream@@QEAAAEAV1@AEAE@Z */
3610 DEFINE_THISCALL_WRAPPER(istream_get_char, 8)
3611 istream* __thiscall istream_get_char(istream *this, char *ch)
3613 istream_internal_get_char(this, ch);
3614 return this;
3617 /* ?get@istream@@QAEHXZ */
3618 /* ?get@istream@@QEAAHXZ */
3619 DEFINE_THISCALL_WRAPPER(istream_get, 4)
3620 int __thiscall istream_get(istream *this)
3622 return istream_internal_get_char(this, NULL);
3625 /* ?get@istream@@QAEAAV1@AAVstreambuf@@D@Z */
3626 /* ?get@istream@@QEAAAEAV1@AEAVstreambuf@@D@Z */
3627 DEFINE_THISCALL_WRAPPER(istream_get_sb, 12)
3628 istream* __thiscall istream_get_sb(istream *this, streambuf *sb, char delim)
3630 ios *base = istream_get_ios(this);
3631 int ch;
3633 TRACE("(%p %p %c)\n", this, sb, delim);
3635 if (istream_ipfx(this, 1)) {
3636 for (ch = streambuf_sgetc(base->sb); ch != delim; ch = streambuf_snextc(base->sb)) {
3637 if (ch == EOF) {
3638 base->state |= IOSTATE_eofbit;
3639 break;
3641 if (streambuf_sputc(sb, ch) == EOF)
3642 base->state |= IOSTATE_failbit;
3643 this->count++;
3645 istream_isfx(this);
3647 return this;
3650 /* ?getline@istream@@QAEAAV1@PACHD@Z */
3651 /* ?getline@istream@@QEAAAEAV1@PEACHD@Z */
3652 /* ?getline@istream@@QAEAAV1@PADHD@Z */
3653 /* ?getline@istream@@QEAAAEAV1@PEADHD@Z */
3654 /* ?getline@istream@@QAEAAV1@PAEHD@Z */
3655 /* ?getline@istream@@QEAAAEAV1@PEAEHD@Z */
3656 DEFINE_THISCALL_WRAPPER(istream_getline, 16)
3657 istream* __thiscall istream_getline(istream *this, char *str, int count, char delim)
3659 ios *base = istream_get_ios(this);
3661 TRACE("(%p %p %d %c)\n", this, str, count, delim);
3663 ios_lock(base);
3664 this->extract_delim++;
3665 istream_get_str_delim(this, str, count, (unsigned char) delim);
3666 ios_unlock(base);
3667 return this;
3670 /* ?ignore@istream@@QAEAAV1@HH@Z */
3671 /* ?ignore@istream@@QEAAAEAV1@HH@Z */
3672 DEFINE_THISCALL_WRAPPER(istream_ignore, 12)
3673 istream* __thiscall istream_ignore(istream *this, int count, int delim)
3675 ios *base = istream_get_ios(this);
3677 TRACE("(%p %d %d)\n", this, count, delim);
3679 ios_lock(base);
3680 this->extract_delim++;
3681 istream_get_str_delim(this, NULL, count + 1, delim);
3682 ios_unlock(base);
3683 return this;
3686 /* ?peek@istream@@QAEHXZ */
3687 /* ?peek@istream@@QEAAHXZ */
3688 DEFINE_THISCALL_WRAPPER(istream_peek, 4)
3689 int __thiscall istream_peek(istream *this)
3691 ios *base = istream_get_ios(this);
3692 int ret = EOF;
3694 TRACE("(%p)\n", this);
3696 if (istream_ipfx(this, 1)) {
3697 ret = streambuf_sgetc(base->sb);
3698 istream_isfx(this);
3700 return ret;
3703 /* ?putback@istream@@QAEAAV1@D@Z */
3704 /* ?putback@istream@@QEAAAEAV1@D@Z */
3705 DEFINE_THISCALL_WRAPPER(istream_putback, 8)
3706 istream* __thiscall istream_putback(istream *this, char ch)
3708 ios *base = istream_get_ios(this);
3710 TRACE("(%p %c)\n", this, ch);
3712 if (ios_good(base)) {
3713 ios_lockbuf(base);
3714 if (streambuf_sputbackc(base->sb, ch) == EOF)
3715 ios_clear(base, base->state | IOSTATE_failbit);
3716 ios_unlockbuf(base);
3718 return this;
3721 /* ?read@istream@@QAEAAV1@PACH@Z */
3722 /* ?read@istream@@QEAAAEAV1@PEACH@Z */
3723 /* ?read@istream@@QAEAAV1@PADH@Z */
3724 /* ?read@istream@@QEAAAEAV1@PEADH@Z */
3725 /* ?read@istream@@QAEAAV1@PAEH@Z */
3726 /* ?read@istream@@QEAAAEAV1@PEAEH@Z */
3727 DEFINE_THISCALL_WRAPPER(istream_read, 12)
3728 istream* __thiscall istream_read(istream *this, char *str, int count)
3730 ios *base = istream_get_ios(this);
3732 TRACE("(%p %p %d)\n", this, str, count);
3734 if (istream_ipfx(this, 1)) {
3735 if ((this->count = streambuf_sgetn(base->sb, str, count)) != count)
3736 base->state = IOSTATE_eofbit | IOSTATE_failbit;
3737 istream_isfx(this);
3739 return this;
3742 /* ?seekg@istream@@QAEAAV1@J@Z */
3743 /* ?seekg@istream@@QEAAAEAV1@J@Z */
3744 DEFINE_THISCALL_WRAPPER(istream_seekg, 8)
3745 istream* __thiscall istream_seekg(istream *this, streampos pos)
3747 ios *base = istream_get_ios(this);
3749 TRACE("(%p %d)\n", this, pos);
3751 ios_lockbuf(base);
3752 if (streambuf_seekpos(base->sb, pos, OPENMODE_in) == EOF)
3753 ios_clear(base, base->state | IOSTATE_failbit);
3754 ios_unlockbuf(base);
3755 return this;
3758 /* ?seekg@istream@@QAEAAV1@JW4seek_dir@ios@@@Z */
3759 /* ?seekg@istream@@QEAAAEAV1@JW4seek_dir@ios@@@Z */
3760 DEFINE_THISCALL_WRAPPER(istream_seekg_offset, 12)
3761 istream* __thiscall istream_seekg_offset(istream *this, streamoff off, ios_seek_dir dir)
3763 ios *base = istream_get_ios(this);
3765 TRACE("(%p %d %d)\n", this, off, dir);
3767 ios_lockbuf(base);
3768 if (call_streambuf_seekoff(base->sb, off, dir, OPENMODE_in) == EOF)
3769 ios_clear(base, base->state | IOSTATE_failbit);
3770 ios_unlockbuf(base);
3771 return this;
3774 /* ?sync@istream@@QAEHXZ */
3775 /* ?sync@istream@@QEAAHXZ */
3776 DEFINE_THISCALL_WRAPPER(istream_sync, 4)
3777 int __thiscall istream_sync(istream *this)
3779 ios *base = istream_get_ios(this);
3780 int ret;
3782 TRACE("(%p)\n", this);
3784 ios_lockbuf(base);
3785 if ((ret = call_streambuf_sync(base->sb)) == EOF)
3786 ios_clear(base, base->state | IOSTATE_badbit | IOSTATE_failbit);
3787 ios_unlockbuf(base);
3788 return ret;
3791 /* ?tellg@istream@@QAEJXZ */
3792 /* ?tellg@istream@@QEAAJXZ */
3793 DEFINE_THISCALL_WRAPPER(istream_tellg, 4)
3794 streampos __thiscall istream_tellg(istream *this)
3796 ios *base = istream_get_ios(this);
3797 streampos pos;
3799 TRACE("(%p)\n", this);
3801 ios_lockbuf(base);
3802 if ((pos = call_streambuf_seekoff(base->sb, 0, SEEKDIR_cur, OPENMODE_in)) == EOF)
3803 ios_clear(base, base->state | IOSTATE_failbit);
3804 ios_unlockbuf(base);
3805 return pos;
3808 static int getint_is_valid_digit(char ch, int base)
3810 if (base == 8) return (ch >= '0' && ch <= '7');
3811 if (base == 16) return isxdigit(ch);
3812 return isdigit(ch);
3815 /* ?getint@istream@@AAEHPAD@Z */
3816 /* ?getint@istream@@AEAAHPEAD@Z */
3817 DEFINE_THISCALL_WRAPPER(istream_getint, 8)
3818 int __thiscall istream_getint(istream *this, char *str)
3820 ios *base = istream_get_ios(this);
3821 int ch, num_base = 0, i = 0;
3822 BOOL scan_sign = TRUE, scan_prefix = TRUE, scan_x = FALSE, valid_integer = FALSE;
3824 TRACE("(%p %p)\n", this, str);
3826 if (istream_ipfx(this, 0)) {
3827 num_base = (base->flags & FLAGS_dec) ? 10 :
3828 (base->flags & FLAGS_hex) ? 16 :
3829 (base->flags & FLAGS_oct) ? 8 : 0; /* 0 = autodetect */
3830 /* scan valid characters, up to 15 (hard limit on Windows) */
3831 for (ch = streambuf_sgetc(base->sb); i < 15; ch = streambuf_snextc(base->sb)) {
3832 if ((ch == '+' || ch == '-') && scan_sign) {
3833 /* no additional sign allowed */
3834 scan_sign = FALSE;
3835 } else if ((ch == 'x' || ch == 'X') && scan_x) {
3836 /* only hex digits can (and must) follow */
3837 scan_x = valid_integer = FALSE;
3838 num_base = 16;
3839 } else if (ch == '0' && scan_prefix) {
3840 /* might be the octal prefix, the beginning of the hex prefix or a decimal zero */
3841 scan_sign = scan_prefix = FALSE;
3842 scan_x = !num_base || num_base == 16;
3843 valid_integer = TRUE;
3844 if (!num_base)
3845 num_base = 8;
3846 } else if (getint_is_valid_digit(ch, num_base)) {
3847 /* only digits in the corresponding base can follow */
3848 scan_sign = scan_prefix = scan_x = FALSE;
3849 valid_integer = TRUE;
3850 } else {
3851 /* unexpected character, stop scanning */
3852 if (!valid_integer) {
3853 /* the result is not a valid integer */
3854 base->state |= IOSTATE_failbit;
3855 /* put any extracted character back into the stream */
3856 while (i > 0)
3857 if (streambuf_sputbackc(base->sb, str[--i]) == EOF)
3858 base->state |= IOSTATE_badbit; /* characters have been lost for good */
3859 } else if (ch == EOF) {
3860 base->state |= IOSTATE_eofbit;
3861 if (scan_x && !(base->flags & ios_basefield)) {
3862 /* when autodetecting, a single zero followed by EOF is regarded as decimal */
3863 num_base = 0;
3866 break;
3868 str[i++] = ch;
3870 /* append a null terminator */
3871 str[i] = 0;
3872 istream_isfx(this);
3874 return num_base;
3877 /* ?getdouble@istream@@AAEHPADH@Z */
3878 /* ?getdouble@istream@@AEAAHPEADH@Z */
3879 DEFINE_THISCALL_WRAPPER(istream_getdouble, 12)
3880 int __thiscall istream_getdouble(istream *this, char *str, int count)
3882 ios *base = istream_get_ios(this);
3883 int ch, i = 0;
3884 BOOL scan_sign = TRUE, scan_dot = TRUE, scan_exp = TRUE,
3885 valid_mantissa = FALSE, valid_exponent = FALSE;
3887 TRACE("(%p %p %d)\n", this, str, count);
3889 if (istream_ipfx(this, 0)) {
3890 if (!count) {
3891 /* can't output anything */
3892 base->state |= IOSTATE_failbit;
3893 i = -1;
3894 } else {
3895 /* valid mantissas: +d. +.d +d.d (where d are sequences of digits and the sign is optional) */
3896 /* valid exponents: e+d E+d (where d are sequences of digits and the sign is optional) */
3897 for (ch = streambuf_sgetc(base->sb); i < count; ch = streambuf_snextc(base->sb)) {
3898 if ((ch == '+' || ch == '-') && scan_sign) {
3899 /* no additional sign allowed */
3900 scan_sign = FALSE;
3901 } else if (ch == '.' && scan_dot) {
3902 /* no sign or additional dot allowed */
3903 scan_sign = scan_dot = FALSE;
3904 } else if ((ch == 'e' || ch == 'E') && scan_exp) {
3905 /* sign is allowed again but not dots or exponents */
3906 scan_sign = TRUE;
3907 scan_dot = scan_exp = FALSE;
3908 } else if (isdigit(ch)) {
3909 if (scan_exp)
3910 valid_mantissa = TRUE;
3911 else
3912 valid_exponent = TRUE;
3913 /* no sign allowed after a digit */
3914 scan_sign = FALSE;
3915 } else {
3916 /* unexpected character, stop scanning */
3917 /* check whether the result is a valid double */
3918 if (!scan_exp && !valid_exponent) {
3919 /* put the last character back into the stream, usually the 'e' or 'E' */
3920 if (streambuf_sputbackc(base->sb, str[i--]) == EOF)
3921 base->state |= IOSTATE_badbit; /* characters have been lost for good */
3922 } else if (ch == EOF)
3923 base->state |= IOSTATE_eofbit;
3924 if (!valid_mantissa)
3925 base->state |= IOSTATE_failbit;
3926 break;
3928 str[i++] = ch;
3930 /* check if character limit has been reached */
3931 if (i == count) {
3932 base->state |= IOSTATE_failbit;
3933 i--;
3935 /* append a null terminator */
3936 str[i] = 0;
3938 istream_isfx(this);
3940 return i;
3943 /* ??5istream@@QAEAAV0@AAC@Z */
3944 /* ??5istream@@QEAAAEAV0@AEAC@Z */
3945 /* ??5istream@@QAEAAV0@AAD@Z */
3946 /* ??5istream@@QEAAAEAV0@AEAD@Z */
3947 /* ??5istream@@QAEAAV0@AAE@Z */
3948 /* ??5istream@@QEAAAEAV0@AEAE@Z */
3949 DEFINE_THISCALL_WRAPPER(istream_read_char, 8)
3950 istream* __thiscall istream_read_char(istream *this, char *ch)
3952 ios *base = istream_get_ios(this);
3953 int ret;
3955 TRACE("(%p %p)\n", this, ch);
3957 if (istream_ipfx(this, 0)) {
3958 if ((ret = streambuf_sbumpc(base->sb)) == EOF)
3959 base->state |= IOSTATE_eofbit | IOSTATE_failbit;
3960 else
3961 *ch = ret;
3962 istream_isfx(this);
3964 return this;
3967 /* ??5istream@@QAEAAV0@PAC@Z */
3968 /* ??5istream@@QEAAAEAV0@PEAC@Z */
3969 /* ??5istream@@QAEAAV0@PAD@Z */
3970 /* ??5istream@@QEAAAEAV0@PEAD@Z */
3971 /* ??5istream@@QAEAAV0@PAE@Z */
3972 /* ??5istream@@QEAAAEAV0@PEAE@Z */
3973 DEFINE_THISCALL_WRAPPER(istream_read_str, 8)
3974 istream* __thiscall istream_read_str(istream *this, char *str)
3976 ios *base = istream_get_ios(this);
3977 int ch, count = 0;
3979 TRACE("(%p %p)\n", this, str);
3981 if (istream_ipfx(this, 0)) {
3982 if (str) {
3983 for (ch = streambuf_sgetc(base->sb);
3984 count < (unsigned int) base->width - 1 && !isspace(ch);
3985 ch = streambuf_snextc(base->sb)) {
3986 if (ch == EOF) {
3987 base->state |= IOSTATE_eofbit;
3988 break;
3990 str[count++] = ch;
3993 if (!count) /* nothing to output */
3994 base->state |= IOSTATE_failbit;
3995 else /* append a null terminator */
3996 str[count] = 0;
3997 base->width = 0;
3998 istream_isfx(this);
4000 return this;
4003 static LONG istream_internal_read_integer(istream *this, LONG min_value, LONG max_value, BOOL set_flag)
4005 ios *base = istream_get_ios(this);
4006 char buffer[16];
4007 int num_base;
4008 LONG ret;
4010 TRACE("(%p %d %d %d)\n", this, min_value, max_value, set_flag);
4012 num_base = istream_getint(this, buffer);
4013 errno = 0;
4014 ret = strtol(buffer, NULL, num_base);
4015 /* check for overflow and whether the value fits in the output var */
4016 if (set_flag && errno == ERANGE) {
4017 base->state |= IOSTATE_failbit;
4018 } else if (ret > max_value) {
4019 base->state |= IOSTATE_failbit;
4020 ret = max_value;
4021 } else if (ret < min_value) {
4022 base->state |= IOSTATE_failbit;
4023 ret = min_value;
4025 return ret;
4028 static ULONG istream_internal_read_unsigned_integer(istream *this, LONG min_value, ULONG max_value)
4030 ios *base = istream_get_ios(this);
4031 char buffer[16];
4032 int num_base;
4033 ULONG ret;
4035 TRACE("(%p %d %u)\n", this, min_value, max_value);
4037 num_base = istream_getint(this, buffer);
4038 errno = 0;
4039 ret = strtoul(buffer, NULL, num_base);
4040 /* check for overflow and whether the value fits in the output var */
4041 if ((ret == ULONG_MAX && errno == ERANGE) ||
4042 (ret > max_value && ret < (ULONG) min_value)) {
4043 base->state |= IOSTATE_failbit;
4044 ret = max_value;
4046 return ret;
4049 /* ??5istream@@QAEAAV0@AAF@Z */
4050 /* ??5istream@@QEAAAEAV0@AEAF@Z */
4051 DEFINE_THISCALL_WRAPPER(istream_read_short, 8)
4052 istream* __thiscall istream_read_short(istream *this, short *p)
4054 if (istream_ipfx(this, 0)) {
4055 *p = istream_internal_read_integer(this, SHRT_MIN, SHRT_MAX, FALSE);
4056 istream_isfx(this);
4058 return this;
4061 /* ??5istream@@QAEAAV0@AAG@Z */
4062 /* ??5istream@@QEAAAEAV0@AEAG@Z */
4063 DEFINE_THISCALL_WRAPPER(istream_read_unsigned_short, 8)
4064 istream* __thiscall istream_read_unsigned_short(istream *this, unsigned short *p)
4066 if (istream_ipfx(this, 0)) {
4067 *p = istream_internal_read_unsigned_integer(this, SHRT_MIN, USHRT_MAX);
4068 istream_isfx(this);
4070 return this;
4073 /* ??5istream@@QAEAAV0@AAH@Z */
4074 /* ??5istream@@QEAAAEAV0@AEAH@Z */
4075 DEFINE_THISCALL_WRAPPER(istream_read_int, 8)
4076 istream* __thiscall istream_read_int(istream *this, int *p)
4078 if (istream_ipfx(this, 0)) {
4079 *p = istream_internal_read_integer(this, INT_MIN, INT_MAX, FALSE);
4080 istream_isfx(this);
4082 return this;
4085 /* ??5istream@@QAEAAV0@AAI@Z */
4086 /* ??5istream@@QEAAAEAV0@AEAI@Z */
4087 DEFINE_THISCALL_WRAPPER(istream_read_unsigned_int, 8)
4088 istream* __thiscall istream_read_unsigned_int(istream *this, unsigned int *p)
4090 if (istream_ipfx(this, 0)) {
4091 *p = istream_internal_read_unsigned_integer(this, INT_MIN, UINT_MAX);
4092 istream_isfx(this);
4094 return this;
4097 /* ??5istream@@QAEAAV0@AAJ@Z */
4098 /* ??5istream@@QEAAAEAV0@AEAJ@Z */
4099 DEFINE_THISCALL_WRAPPER(istream_read_long, 8)
4100 istream* __thiscall istream_read_long(istream *this, LONG *p)
4102 if (istream_ipfx(this, 0)) {
4103 *p = istream_internal_read_integer(this, LONG_MIN, LONG_MAX, TRUE);
4104 istream_isfx(this);
4106 return this;
4109 /* ??5istream@@QAEAAV0@AAK@Z */
4110 /* ??5istream@@QEAAAEAV0@AEAK@Z */
4111 DEFINE_THISCALL_WRAPPER(istream_read_unsigned_long, 8)
4112 istream* __thiscall istream_read_unsigned_long(istream *this, ULONG *p)
4114 if (istream_ipfx(this, 0)) {
4115 *p = istream_internal_read_unsigned_integer(this, LONG_MIN, ULONG_MAX);
4116 istream_isfx(this);
4118 return this;
4121 static BOOL istream_internal_read_float(istream *this, int max_chars, double *out)
4123 char buffer[32];
4124 BOOL read = FALSE;
4126 TRACE("(%p %d %p)\n", this, max_chars, out);
4128 if (istream_ipfx(this, 0)) {
4129 /* character count is limited on Windows */
4130 if (istream_getdouble(this, buffer, max_chars) > 0) {
4131 *out = strtod(buffer, NULL);
4132 read = TRUE;
4134 istream_isfx(this);
4136 return read;
4139 /* ??5istream@@QAEAAV0@AAM@Z */
4140 /* ??5istream@@QEAAAEAV0@AEAM@Z */
4141 DEFINE_THISCALL_WRAPPER(istream_read_float, 8)
4142 istream* __thiscall istream_read_float(istream *this, float *f)
4144 double tmp;
4145 if (istream_internal_read_float(this, 20, &tmp)) {
4146 /* check whether the value fits in the output var */
4147 if (tmp > FLT_MAX)
4148 tmp = FLT_MAX;
4149 else if (tmp < -FLT_MAX)
4150 tmp = -FLT_MAX;
4151 else if (tmp > 0 && tmp < FLT_MIN)
4152 tmp = FLT_MIN;
4153 else if (tmp < 0 && tmp > -FLT_MIN)
4154 tmp = -FLT_MIN;
4155 *f = tmp;
4157 return this;
4160 /* ??5istream@@QAEAAV0@AAN@Z */
4161 /* ??5istream@@QEAAAEAV0@AEAN@Z */
4162 DEFINE_THISCALL_WRAPPER(istream_read_double, 8)
4163 istream* __thiscall istream_read_double(istream *this, double *d)
4165 istream_internal_read_float(this, 28, d);
4166 return this;
4169 /* ??5istream@@QAEAAV0@AAO@Z */
4170 /* ??5istream@@QEAAAEAV0@AEAO@Z */
4171 DEFINE_THISCALL_WRAPPER(istream_read_long_double, 8)
4172 istream* __thiscall istream_read_long_double(istream *this, double *ld)
4174 istream_internal_read_float(this, 32, ld);
4175 return this;
4178 /* ??5istream@@QAEAAV0@PAVstreambuf@@@Z */
4179 /* ??5istream@@QEAAAEAV0@PEAVstreambuf@@@Z */
4180 DEFINE_THISCALL_WRAPPER(istream_read_streambuf, 8)
4181 istream* __thiscall istream_read_streambuf(istream *this, streambuf *sb)
4183 ios *base = istream_get_ios(this);
4184 int ch;
4186 TRACE("(%p %p)\n", this, sb);
4188 if (istream_ipfx(this, 0)) {
4189 while ((ch = streambuf_sbumpc(base->sb)) != EOF)
4190 if (streambuf_sputc(sb, ch) == EOF)
4191 base->state |= IOSTATE_failbit;
4192 istream_isfx(this);
4194 return this;
4197 /* ??5istream@@QAEAAV0@P6AAAV0@AAV0@@Z@Z */
4198 /* ??5istream@@QEAAAEAV0@P6AAEAV0@AEAV0@@Z@Z */
4199 DEFINE_THISCALL_WRAPPER(istream_read_manip, 8)
4200 istream* __thiscall istream_read_manip(istream *this, istream* (__cdecl *func)(istream*))
4202 TRACE("(%p %p)\n", this, func);
4203 return func(this);
4206 /* ??5istream@@QAEAAV0@P6AAAVios@@AAV1@@Z@Z */
4207 /* ??5istream@@QEAAAEAV0@P6AAEAVios@@AEAV1@@Z@Z */
4208 DEFINE_THISCALL_WRAPPER(istream_read_ios_manip, 8)
4209 istream* __thiscall istream_read_ios_manip(istream *this, ios* (__cdecl *func)(ios*))
4211 TRACE("(%p %p)\n", this, func);
4212 func(istream_get_ios(this));
4213 return this;
4216 /* ?ws@@YAAAVistream@@AAV1@@Z */
4217 /* ?ws@@YAAEAVistream@@AEAV1@@Z */
4218 istream* __cdecl istream_ws(istream *this)
4220 TRACE("(%p)\n", this);
4221 istream_eatwhite(this);
4222 return this;
4225 /* ??0istream_withassign@@QAE@ABV0@@Z */
4226 /* ??0istream_withassign@@QEAA@AEBV0@@Z */
4227 DEFINE_THISCALL_WRAPPER(istream_withassign_copy_ctor, 12)
4228 istream* __thiscall istream_withassign_copy_ctor(istream *this, const istream *copy, BOOL virt_init)
4230 ios *base, *base_copy;
4232 TRACE("(%p %p %d)\n", this, copy, virt_init);
4234 base_copy = istream_get_ios(copy);
4235 if (virt_init) {
4236 this->vbtable = istream_vbtable;
4237 base = istream_get_ios(this);
4238 ios_copy_ctor(base, base_copy);
4239 } else
4240 base = istream_get_ios(this);
4241 ios_init(base, base_copy->sb);
4242 base->vtable = &MSVCP_istream_withassign_vtable;
4243 base->flags |= FLAGS_skipws;
4244 this->extract_delim = 0;
4245 this->count = 0;
4246 return this;
4249 /* ??0istream_withassign@@QAE@PAVstreambuf@@@Z */
4250 /* ??0istream_withassign@@QEAA@PEAVstreambuf@@@Z */
4251 DEFINE_THISCALL_WRAPPER(istream_withassign_sb_ctor, 12)
4252 istream* __thiscall istream_withassign_sb_ctor(istream *this, streambuf *sb, BOOL virt_init)
4254 ios *base;
4256 TRACE("(%p %p %d)\n", this, sb, virt_init);
4258 istream_sb_ctor(this, sb, virt_init);
4259 base = istream_get_ios(this);
4260 base->vtable = &MSVCP_istream_withassign_vtable;
4261 return this;
4264 /* ??0istream_withassign@@QAE@XZ */
4265 /* ??0istream_withassign@@QEAA@XZ */
4266 DEFINE_THISCALL_WRAPPER(istream_withassign_ctor, 8)
4267 istream* __thiscall istream_withassign_ctor(istream *this, BOOL virt_init)
4269 ios *base;
4271 TRACE("(%p %d)\n", this, virt_init);
4273 istream_ctor(this, virt_init);
4274 base = istream_get_ios(this);
4275 base->vtable = &MSVCP_istream_withassign_vtable;
4276 return this;
4279 /* ??0istrstream@@QAE@ABV0@@Z */
4280 /* ??0istrstream@@QEAA@AEBV0@@Z */
4281 DEFINE_THISCALL_WRAPPER(istrstream_copy_ctor, 12)
4282 istream* __thiscall istrstream_copy_ctor(istream *this, const istream *copy, BOOL virt_init)
4284 TRACE("(%p %p %d)\n", this, copy, virt_init);
4285 istream_withassign_copy_ctor(this, copy, virt_init);
4286 istream_get_ios(this)->vtable = &MSVCP_istrstream_vtable;
4287 return this;
4290 /* ??0istrstream@@QAE@PADH@Z */
4291 /* ??0istrstream@@QEAA@PEADH@Z */
4292 DEFINE_THISCALL_WRAPPER(istrstream_buffer_ctor, 16)
4293 istream* __thiscall istrstream_buffer_ctor(istream *this, char *buffer, int length, BOOL virt_init)
4295 ios *base;
4296 strstreambuf *ssb = MSVCRT_operator_new(sizeof(strstreambuf));
4298 TRACE("(%p %p %d %d)\n", this, buffer, length, virt_init);
4300 if (!ssb) {
4301 FIXME("out of memory\n");
4302 return NULL;
4305 strstreambuf_buffer_ctor(ssb, buffer, length, NULL);
4306 istream_sb_ctor(this, &ssb->base, virt_init);
4308 base = istream_get_ios(this);
4309 base->vtable = &MSVCP_istrstream_vtable;
4310 base->delbuf = 1;
4311 return this;
4314 /* ??0istrstream@@QAE@PAD@Z */
4315 /* ??0istrstream@@QEAA@PEAD@Z */
4316 DEFINE_THISCALL_WRAPPER(istrstream_str_ctor, 12)
4317 istream* __thiscall istrstream_str_ctor(istream *this, char *str, BOOL virt_init)
4319 return istrstream_buffer_ctor(this, str, 0, virt_init);
4322 /* ?rdbuf@istrstream@@QBEPAVstrstreambuf@@XZ */
4323 /* ?rdbuf@istrstream@@QEBAPEAVstrstreambuf@@XZ */
4324 DEFINE_THISCALL_WRAPPER(istrstream_rdbuf, 4)
4325 strstreambuf* __thiscall istrstream_rdbuf(const istream *this)
4327 return (strstreambuf*) istream_get_ios(this)->sb;
4330 /* ?str@istrstream@@QAEPADXZ */
4331 /* ?str@istrstream@@QEAAPEADXZ */
4332 DEFINE_THISCALL_WRAPPER(istrstream_str, 4)
4333 char* __thiscall istrstream_str(istream *this)
4335 return strstreambuf_str(istrstream_rdbuf(this));
4338 /* ??0ifstream@@QAE@ABV0@@Z */
4339 /* ??0ifstream@@QEAA@AEBV0@@Z */
4340 DEFINE_THISCALL_WRAPPER(ifstream_copy_ctor, 12)
4341 istream* __thiscall ifstream_copy_ctor(istream *this, const istream *copy, BOOL virt_init)
4343 TRACE("(%p %p %d)\n", this, copy, virt_init);
4344 istream_withassign_copy_ctor(this, copy, virt_init);
4345 istream_get_ios(this)->vtable = &MSVCP_ifstream_vtable;
4346 return this;
4349 /* ??0ifstream@@QAE@HPADH@Z */
4350 /* ??0ifstream@@QEAA@HPEADH@Z */
4351 DEFINE_THISCALL_WRAPPER(ifstream_buffer_ctor, 20)
4352 istream* __thiscall ifstream_buffer_ctor(istream *this, filedesc fd, char *buffer, int length, BOOL virt_init)
4354 ios *base;
4355 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
4357 TRACE("(%p %d %p %d %d)\n", this, fd, buffer, length, virt_init);
4359 if (!fb) {
4360 FIXME("out of memory\n");
4361 return NULL;
4364 filebuf_fd_reserve_ctor(fb, fd, buffer, length);
4365 istream_sb_ctor(this, &fb->base, virt_init);
4367 base = istream_get_ios(this);
4368 base->vtable = &MSVCP_ifstream_vtable;
4369 base->delbuf = 1;
4371 return this;
4374 /* ??0ifstream@@QAE@H@Z */
4375 /* ??0ifstream@@QEAA@H@Z */
4376 DEFINE_THISCALL_WRAPPER(ifstream_fd_ctor, 12)
4377 istream* __thiscall ifstream_fd_ctor(istream *this, filedesc fd, BOOL virt_init)
4379 ios *base;
4380 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
4382 TRACE("(%p %d %d)\n", this, fd, virt_init);
4384 if (!fb) {
4385 FIXME("out of memory\n");
4386 return NULL;
4389 filebuf_fd_ctor(fb, fd);
4390 istream_sb_ctor(this, &fb->base, virt_init);
4392 base = istream_get_ios(this);
4393 base->vtable = &MSVCP_ifstream_vtable;
4394 base->delbuf = 1;
4396 return this;
4399 /* ??0ifstream@@QAE@PBDHH@Z */
4400 /* ??0ifstream@@QEAA@PEBDHH@Z */
4401 DEFINE_THISCALL_WRAPPER(ifstream_open_ctor, 20)
4402 istream* __thiscall ifstream_open_ctor(istream *this, const char *name, ios_open_mode mode, int protection, BOOL virt_init)
4404 ios *base;
4405 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
4407 TRACE("(%p %s %d %d %d)\n", this, name, mode, protection, virt_init);
4409 if (!fb) {
4410 FIXME("out of memory\n");
4411 return NULL;
4414 filebuf_ctor(fb);
4415 istream_sb_ctor(this, &fb->base, virt_init);
4417 base = istream_get_ios(this);
4418 base->vtable = &MSVCP_ifstream_vtable;
4419 base->delbuf = 1;
4421 if (filebuf_open(fb, name, mode|OPENMODE_in, protection) == NULL)
4422 base->state |= IOSTATE_failbit;
4423 return this;
4426 /* ??0ifstream@@QAE@XZ */
4427 /* ??0ifstream@@QEAA@XZ */
4428 DEFINE_THISCALL_WRAPPER(ifstream_ctor, 8)
4429 istream* __thiscall ifstream_ctor(istream *this, BOOL virt_init)
4431 return ifstream_fd_ctor(this, -1, virt_init);
4434 /* ?rdbuf@ifstream@@QBEPAVfilebuf@@XZ */
4435 /* ?rdbuf@ifstream@@QEBAPEAVfilebuf@@XZ */
4436 DEFINE_THISCALL_WRAPPER(ifstream_rdbuf, 4)
4437 filebuf* __thiscall ifstream_rdbuf(const istream *this)
4439 TRACE("(%p)\n", this);
4440 return (filebuf*) istream_get_ios(this)->sb;
4443 /* ?fd@ifstream@@QBEHXZ */
4444 /* ?fd@ifstream@@QEBAHXZ */
4445 DEFINE_THISCALL_WRAPPER(ifstream_fd, 4)
4446 filedesc __thiscall ifstream_fd(istream *this)
4448 TRACE("(%p)\n", this);
4449 return filebuf_fd(ifstream_rdbuf(this));
4452 /* ?attach@ifstream@@QAEXH@Z */
4453 /* ?attach@ifstream@@QEAAXH@Z */
4454 DEFINE_THISCALL_WRAPPER(ifstream_attach, 8)
4455 void __thiscall ifstream_attach(istream *this, filedesc fd)
4457 ios *base = istream_get_ios(this);
4458 TRACE("(%p %d)\n", this, fd);
4459 if (filebuf_attach(ifstream_rdbuf(this), fd) == NULL)
4460 ios_clear(base, base->state | IOSTATE_failbit);
4463 /* ?close@ifstream@@QAEXXZ */
4464 /* ?close@ifstream@@QEAAXXZ */
4465 DEFINE_THISCALL_WRAPPER(ifstream_close, 4)
4466 void __thiscall ifstream_close(istream *this)
4468 ios *base = istream_get_ios(this);
4469 TRACE("(%p)\n", this);
4470 if (filebuf_close(ifstream_rdbuf(this)) == NULL)
4471 ios_clear(base, base->state | IOSTATE_failbit);
4472 else
4473 ios_clear(base, IOSTATE_goodbit);
4476 /* ?is_open@ifstream@@QBEHXZ */
4477 /* ?is_open@ifstream@@QEBAHXZ */
4478 DEFINE_THISCALL_WRAPPER(ifstream_is_open, 4)
4479 int __thiscall ifstream_is_open(const istream *this)
4481 TRACE("(%p)\n", this);
4482 return filebuf_is_open(ifstream_rdbuf(this));
4485 /* ?open@ifstream@@QAEXPBDHH@Z */
4486 /* ?open@ifstream@@QEAAXPEBDHH@Z */
4487 DEFINE_THISCALL_WRAPPER(ifstream_open, 16)
4488 void __thiscall ifstream_open(istream *this, const char *name, ios_open_mode mode, int protection)
4490 ios *base = istream_get_ios(this);
4491 TRACE("(%p %s %d %d)\n", this, name, mode, protection);
4492 if (filebuf_open(ifstream_rdbuf(this), name, mode|OPENMODE_in, protection) == NULL)
4493 ios_clear(base, base->state | IOSTATE_failbit);
4496 /* ?setbuf@ifstream@@QAEPAVstreambuf@@PADH@Z */
4497 /* ?setbuf@ifstream@@QEAAPEAVstreambuf@@PEADH@Z */
4498 DEFINE_THISCALL_WRAPPER(ifstream_setbuf, 12)
4499 streambuf* __thiscall ifstream_setbuf(istream *this, char *buffer, int length)
4501 ios *base = istream_get_ios(this);
4502 filebuf* fb = ifstream_rdbuf(this);
4504 TRACE("(%p %p %d)\n", this, buffer, length);
4506 if (filebuf_is_open(fb)) {
4507 ios_clear(base, base->state | IOSTATE_failbit);
4508 return NULL;
4511 return filebuf_setbuf(fb, buffer, length);
4514 /* ?setmode@ifstream@@QAEHH@Z */
4515 /* ?setmode@ifstream@@QEAAHH@Z */
4516 DEFINE_THISCALL_WRAPPER(ifstream_setmode, 8)
4517 int __thiscall ifstream_setmode(istream *this, int mode)
4519 TRACE("(%p %d)\n", this, mode);
4520 return filebuf_setmode(ifstream_rdbuf(this), mode);
4523 static inline ios* iostream_to_ios(const iostream *this)
4525 return (ios*)((char*)this + iostream_vbtable_istream[1]);
4528 static inline iostream* ios_to_iostream(const ios *base)
4530 return (iostream*)((char*)base - iostream_vbtable_istream[1]);
4533 /* ??0iostream@@IAE@XZ */
4534 /* ??0iostream@@IEAA@XZ */
4535 DEFINE_THISCALL_WRAPPER(iostream_ctor, 8)
4536 iostream* __thiscall iostream_ctor(iostream *this, BOOL virt_init)
4538 ios *base;
4540 TRACE("(%p %d)\n", this, virt_init);
4542 if (virt_init) {
4543 this->base1.vbtable = iostream_vbtable_istream;
4544 this->base2.vbtable = iostream_vbtable_ostream;
4545 base = istream_get_ios(&this->base1);
4546 ios_ctor(base);
4547 } else
4548 base = istream_get_ios(&this->base1);
4549 istream_ctor(&this->base1, FALSE);
4550 ostream_ctor(&this->base2, FALSE);
4551 base->vtable = &MSVCP_iostream_vtable;
4552 return this;
4555 /* ??0iostream@@QAE@PAVstreambuf@@@Z */
4556 /* ??0iostream@@QEAA@PEAVstreambuf@@@Z */
4557 DEFINE_THISCALL_WRAPPER(iostream_sb_ctor, 12)
4558 iostream* __thiscall iostream_sb_ctor(iostream *this, streambuf *sb, BOOL virt_init)
4560 TRACE("(%p %p %d)\n", this, sb, virt_init);
4561 iostream_ctor(this, virt_init);
4562 ios_init(istream_get_ios(&this->base1), sb);
4563 return this;
4566 /* ??0iostream@@IAE@ABV0@@Z */
4567 /* ??0iostream@@IEAA@AEBV0@@Z */
4568 DEFINE_THISCALL_WRAPPER(iostream_copy_ctor, 12)
4569 iostream* __thiscall iostream_copy_ctor(iostream *this, const iostream *copy, BOOL virt_init)
4571 return iostream_sb_ctor(this, istream_get_ios(&copy->base1)->sb, virt_init);
4574 /* ??1iostream@@UAE@XZ */
4575 /* ??1iostream@@UEAA@XZ */
4576 /* ??1stdiostream@@UAE@XZ */
4577 /* ??1stdiostream@@UEAA@XZ */
4578 /* ??1strstream@@UAE@XZ */
4579 /* ??1strstream@@UEAA@XZ */
4580 /* ??1fstream@@UAE@XZ */
4581 /* ??1fstream@@UEAA@XZ */
4582 DEFINE_THISCALL_WRAPPER(iostream_dtor, 4)
4583 void __thiscall iostream_dtor(ios *base)
4585 iostream *this = ios_to_iostream(base);
4587 TRACE("(%p)\n", this);
4589 ostream_dtor(ostream_to_ios(&this->base2));
4590 istream_dtor(istream_to_ios(&this->base1));
4593 /* ??4iostream@@IAEAAV0@PAVstreambuf@@@Z */
4594 /* ??4iostream@@IEAAAEAV0@PEAVstreambuf@@@Z */
4595 DEFINE_THISCALL_WRAPPER(iostream_assign_sb, 8)
4596 iostream* __thiscall iostream_assign_sb(iostream *this, streambuf *sb)
4598 TRACE("(%p %p)\n", this, sb);
4599 this->base1.count = 0;
4600 ostream_assign_sb(&this->base2, sb);
4601 return this;
4604 /* ??4iostream@@IAEAAV0@AAV0@@Z */
4605 /* ??4iostream@@IEAAAEAV0@AEAV0@@Z */
4606 /* ??4stdiostream@@QAEAAV0@AAV0@@Z */
4607 /* ??4stdiostream@@QEAAAEAV0@AEAV0@@Z */
4608 /* ??4strstream@@QAEAAV0@ABV0@@Z */
4609 /* ??4strstream@@QEAAAEAV0@AEBV0@@Z */
4610 DEFINE_THISCALL_WRAPPER(iostream_assign, 8)
4611 iostream* __thiscall iostream_assign(iostream *this, const iostream *rhs)
4613 return iostream_assign_sb(this, istream_get_ios(&rhs->base1)->sb);
4616 /* ??_Diostream@@QAEXXZ */
4617 /* ??_Diostream@@QEAAXXZ */
4618 /* ??_Dstdiostream@@QAEXXZ */
4619 /* ??_Dstdiostream@@QEAAXXZ */
4620 /* ??_Dstrstream@@QAEXXZ */
4621 /* ??_Dstrstream@@QEAAXXZ */
4622 DEFINE_THISCALL_WRAPPER(iostream_vbase_dtor, 4)
4623 void __thiscall iostream_vbase_dtor(iostream *this)
4625 ios *base = iostream_to_ios(this);
4627 TRACE("(%p)\n", this);
4629 iostream_dtor(base);
4630 ios_dtor(base);
4633 /* ??_Eiostream@@UAEPAXI@Z */
4634 /* ??_Estdiostream@@UAEPAXI@Z */
4635 /* ??_Estrstream@@UAEPAXI@Z */
4636 DEFINE_THISCALL_WRAPPER(iostream_vector_dtor, 8)
4637 iostream* __thiscall iostream_vector_dtor(ios *base, unsigned int flags)
4639 iostream *this = ios_to_iostream(base);
4641 TRACE("(%p %x)\n", this, flags);
4643 if (flags & 2) {
4644 /* we have an array, with the number of elements stored before the first object */
4645 INT_PTR i, *ptr = (INT_PTR *)this-1;
4647 for (i = *ptr-1; i >= 0; i--)
4648 iostream_vbase_dtor(this+i);
4649 MSVCRT_operator_delete(ptr);
4650 } else {
4651 iostream_vbase_dtor(this);
4652 if (flags & 1)
4653 MSVCRT_operator_delete(this);
4655 return this;
4658 /* ??_Giostream@@UAEPAXI@Z */
4659 /* ??_Gstdiostream@@UAEPAXI@Z */
4660 /* ??_Gstrstream@@UAEPAXI@Z */
4661 DEFINE_THISCALL_WRAPPER(iostream_scalar_dtor, 8)
4662 iostream* __thiscall iostream_scalar_dtor(ios *base, unsigned int flags)
4664 iostream *this = ios_to_iostream(base);
4666 TRACE("(%p %x)\n", this, flags);
4668 iostream_vbase_dtor(this);
4669 if (flags & 1) MSVCRT_operator_delete(this);
4670 return this;
4673 static iostream* iostream_internal_copy_ctor(iostream *this, const iostream *copy, const vtable_ptr *vtbl, BOOL virt_init)
4675 ios *base, *base_copy = istream_get_ios(&copy->base1);
4677 if (virt_init) {
4678 this->base1.vbtable = iostream_vbtable_istream;
4679 this->base2.vbtable = iostream_vbtable_ostream;
4680 base = istream_get_ios(&this->base1);
4681 ios_copy_ctor(base, base_copy);
4682 } else
4683 base = istream_get_ios(&this->base1);
4684 ios_init(base, base_copy->sb);
4685 istream_ctor(&this->base1, FALSE);
4686 ostream_ctor(&this->base2, FALSE);
4687 base->vtable = vtbl;
4688 return this;
4691 static iostream* iostream_internal_sb_ctor(iostream *this, streambuf *sb, const vtable_ptr *vtbl, BOOL virt_init)
4693 ios *base;
4695 iostream_ctor(this, virt_init);
4696 base = istream_get_ios(&this->base1);
4697 if (sb)
4698 ios_init(base, sb);
4699 base->vtable = vtbl;
4700 base->delbuf = 1;
4701 return this;
4704 /* ??0strstream@@QAE@ABV0@@Z */
4705 /* ??0strstream@@QEAA@AEBV0@@Z */
4706 DEFINE_THISCALL_WRAPPER(strstream_copy_ctor, 12)
4707 iostream* __thiscall strstream_copy_ctor(iostream *this, const iostream *copy, BOOL virt_init)
4709 TRACE("(%p %p %d)\n", this, copy, virt_init);
4710 return iostream_internal_copy_ctor(this, copy, &MSVCP_strstream_vtable, virt_init);
4713 /* ??0strstream@@QAE@PADHH@Z */
4714 /* ??0strstream@@QEAA@PEADHH@Z */
4715 DEFINE_THISCALL_WRAPPER(strstream_buffer_ctor, 20)
4716 iostream* __thiscall strstream_buffer_ctor(iostream *this, char *buffer, int length, int mode, BOOL virt_init)
4718 strstreambuf *ssb = MSVCRT_operator_new(sizeof(strstreambuf));
4720 TRACE("(%p %p %d %d %d)\n", this, buffer, length, mode, virt_init);
4722 if (!ssb) {
4723 FIXME("out of memory\n");
4724 return NULL;
4727 strstreambuf_buffer_ctor(ssb, buffer, length, buffer);
4729 if ((mode & OPENMODE_out) && (mode & (OPENMODE_app|OPENMODE_ate)))
4730 ssb->base.pptr = buffer + strlen(buffer);
4732 return iostream_internal_sb_ctor(this, &ssb->base, &MSVCP_strstream_vtable, virt_init);
4735 /* ??0strstream@@QAE@XZ */
4736 /* ??0strstream@@QEAA@XZ */
4737 DEFINE_THISCALL_WRAPPER(strstream_ctor, 8)
4738 iostream* __thiscall strstream_ctor(iostream *this, BOOL virt_init)
4740 strstreambuf *ssb = MSVCRT_operator_new(sizeof(strstreambuf));
4742 TRACE("(%p %d)\n", this, virt_init);
4744 if (!ssb) {
4745 FIXME("out of memory\n");
4746 return NULL;
4749 strstreambuf_ctor(ssb);
4751 return iostream_internal_sb_ctor(this, &ssb->base, &MSVCP_strstream_vtable, virt_init);
4754 /* ?pcount@strstream@@QBEHXZ */
4755 /* ?pcount@strstream@@QEBAHXZ */
4756 DEFINE_THISCALL_WRAPPER(strstream_pcount, 4)
4757 int __thiscall strstream_pcount(const iostream *this)
4759 return streambuf_out_waiting(istream_get_ios(&this->base1)->sb);
4762 /* ?rdbuf@strstream@@QBEPAVstrstreambuf@@XZ */
4763 /* ?rdbuf@strstream@@QEBAPEAVstrstreambuf@@XZ */
4764 DEFINE_THISCALL_WRAPPER(strstream_rdbuf, 4)
4765 strstreambuf* __thiscall strstream_rdbuf(const iostream *this)
4767 return (strstreambuf*) istream_get_ios(&this->base1)->sb;
4770 /* ?str@strstream@@QAEPADXZ */
4771 /* ?str@strstream@@QEAAPEADXZ */
4772 DEFINE_THISCALL_WRAPPER(strstream_str, 4)
4773 char* __thiscall strstream_str(iostream *this)
4775 return strstreambuf_str(strstream_rdbuf(this));
4778 /* ??0stdiostream@@QAE@ABV0@@Z */
4779 /* ??0stdiostream@@QEAA@AEBV0@@Z */
4780 DEFINE_THISCALL_WRAPPER(stdiostream_copy_ctor, 12)
4781 iostream* __thiscall stdiostream_copy_ctor(iostream *this, const iostream *copy, BOOL virt_init)
4783 TRACE("(%p %p %d)\n", this, copy, virt_init);
4784 return iostream_internal_copy_ctor(this, copy, &MSVCP_stdiostream_vtable, virt_init);
4787 /* ??0stdiostream@@QAE@PAU_iobuf@@@Z */
4788 /* ??0stdiostream@@QEAA@PEAU_iobuf@@@Z */
4789 DEFINE_THISCALL_WRAPPER(stdiostream_file_ctor, 12)
4790 iostream* __thiscall stdiostream_file_ctor(iostream *this, FILE *file, BOOL virt_init)
4792 stdiobuf *stb = MSVCRT_operator_new(sizeof(stdiobuf));
4794 TRACE("(%p %p %d)\n", this, file, virt_init);
4796 if (!stb) {
4797 FIXME("out of memory\n");
4798 return NULL;
4801 stdiobuf_file_ctor(stb, file);
4803 return iostream_internal_sb_ctor(this, &stb->base, &MSVCP_stdiostream_vtable, virt_init);
4806 /* ?rdbuf@stdiostream@@QBEPAVstdiobuf@@XZ */
4807 /* ?rdbuf@stdiostream@@QEBAPEAVstdiobuf@@XZ */
4808 DEFINE_THISCALL_WRAPPER(stdiostream_rdbuf, 4)
4809 stdiobuf* __thiscall stdiostream_rdbuf(const iostream *this)
4811 return (stdiobuf*) istream_get_ios(&this->base1)->sb;
4814 /* ??0fstream@@QAE@ABV0@@Z */
4815 /* ??0fstream@@QEAA@AEBV0@@Z */
4816 DEFINE_THISCALL_WRAPPER(fstream_copy_ctor, 12)
4817 iostream* __thiscall fstream_copy_ctor(iostream *this, const iostream *copy, BOOL virt_init)
4819 TRACE("(%p %p %d)\n", this, copy, virt_init);
4820 iostream_internal_copy_ctor(this, copy, &MSVCP_fstream_vtable, virt_init);
4821 return this;
4824 /* ??0fstream@@QAE@HPADH@Z */
4825 /* ??0fstream@@QEAA@HPEADH@Z */
4826 DEFINE_THISCALL_WRAPPER(fstream_buffer_ctor, 20)
4827 iostream* __thiscall fstream_buffer_ctor(iostream *this, filedesc fd, char *buffer, int length, BOOL virt_init)
4829 ios *base;
4830 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
4832 TRACE("(%p %d %p %d %d)\n", this, fd, buffer, length, virt_init);
4834 if (!fb) {
4835 FIXME("out of memory\n");
4836 return NULL;
4839 filebuf_fd_reserve_ctor(fb, fd, buffer, length);
4841 iostream_internal_sb_ctor(this, &fb->base, &MSVCP_fstream_vtable, virt_init);
4843 base = istream_get_ios(&this->base1);
4844 base->delbuf = 1;
4846 return this;
4849 /* ??0fstream@@QAE@H@Z */
4850 /* ??0fstream@@QEAA@H@Z */
4851 DEFINE_THISCALL_WRAPPER(fstream_fd_ctor, 12)
4852 iostream* __thiscall fstream_fd_ctor(iostream *this, filedesc fd, BOOL virt_init)
4854 ios *base;
4855 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
4857 TRACE("(%p %d %d)\n", this, fd, virt_init);
4859 if (!fb) {
4860 FIXME("out of memory\n");
4861 return NULL;
4864 filebuf_fd_ctor(fb, fd);
4866 iostream_internal_sb_ctor(this, &fb->base, &MSVCP_fstream_vtable, virt_init);
4868 base = istream_get_ios(&this->base1);
4869 base->delbuf = 1;
4871 return this;
4874 /* ??0fstream@@QAE@PBDHH@Z */
4875 /* ??0fstream@@QEAA@PEBDHH@Z */
4876 DEFINE_THISCALL_WRAPPER(fstream_open_ctor, 20)
4877 iostream* __thiscall fstream_open_ctor(iostream *this, const char *name, ios_open_mode mode, int protection, BOOL virt_init)
4879 ios *base;
4880 filebuf *fb = MSVCRT_operator_new(sizeof(filebuf));
4882 TRACE("(%p %s %d %d %d)\n", this, name, mode, protection, virt_init);
4884 if (!fb) {
4885 FIXME("out of memory\n");
4886 return NULL;
4889 filebuf_ctor(fb);
4891 iostream_internal_sb_ctor(this, &fb->base, &MSVCP_fstream_vtable, virt_init);
4893 base = istream_get_ios(&this->base1);
4894 base->delbuf = 1;
4896 if (filebuf_open(fb, name, mode, protection) == NULL)
4897 base->state |= IOSTATE_failbit;
4898 return this;
4901 /* ??0fstream@@QAE@XZ */
4902 /* ??0fstream@@QEAA@XZ */
4903 DEFINE_THISCALL_WRAPPER(fstream_ctor, 8)
4904 iostream* __thiscall fstream_ctor(iostream *this, BOOL virt_init)
4906 return fstream_fd_ctor(this, -1, virt_init);
4909 /* ?rdbuf@fstream@@QBEPAVfilebuf@@XZ */
4910 /* ?rdbuf@fstream@@QEBAPEAVfilebuf@@XZ */
4911 DEFINE_THISCALL_WRAPPER(fstream_rdbuf, 4)
4912 filebuf* __thiscall fstream_rdbuf(const iostream *this)
4914 TRACE("(%p)\n", this);
4915 return (filebuf*) istream_get_ios(&this->base1)->sb;
4918 /* ?fd@fstream@@QBEHXZ */
4919 /* ?fd@fstream@@QEBAHXZ */
4920 DEFINE_THISCALL_WRAPPER(fstream_fd, 4)
4921 filedesc __thiscall fstream_fd(iostream *this)
4923 TRACE("(%p)\n", this);
4924 return filebuf_fd(fstream_rdbuf(this));
4927 /* ?attach@fstream@@QAEXH@Z */
4928 /* ?attach@fstream@@QEAAXH@Z */
4929 DEFINE_THISCALL_WRAPPER(fstream_attach, 8)
4930 void __thiscall fstream_attach(iostream *this, filedesc fd)
4932 ios *base = istream_get_ios(&this->base1);
4933 TRACE("(%p %d)\n", this, fd);
4934 if (filebuf_attach(fstream_rdbuf(this), fd) == NULL)
4935 ios_clear(base, base->state | IOSTATE_failbit);
4938 /* ?close@fstream@@QAEXXZ */
4939 /* ?close@fstream@@QEAAXXZ */
4940 DEFINE_THISCALL_WRAPPER(fstream_close, 4)
4941 void __thiscall fstream_close(iostream *this)
4943 ios *base = istream_get_ios(&this->base1);
4944 TRACE("(%p)\n", this);
4945 if (filebuf_close(fstream_rdbuf(this)) == NULL)
4946 ios_clear(base, base->state | IOSTATE_failbit);
4947 else
4948 ios_clear(base, IOSTATE_goodbit);
4951 /* ?is_open@fstream@@QBEHXZ */
4952 /* ?is_open@fstream@@QEBAHXZ */
4953 DEFINE_THISCALL_WRAPPER(fstream_is_open, 4)
4954 int __thiscall fstream_is_open(const iostream *this)
4956 TRACE("(%p)\n", this);
4957 return filebuf_is_open(fstream_rdbuf(this));
4960 /* ?open@fstream@@QAEXPBDHH@Z */
4961 /* ?open@fstream@@QEAAXPEBDHH@Z */
4962 DEFINE_THISCALL_WRAPPER(fstream_open, 16)
4963 void __thiscall fstream_open(iostream *this, const char *name, ios_open_mode mode, int protection)
4965 ios *base = istream_get_ios(&this->base1);
4966 TRACE("(%p %s %d %d)\n", this, name, mode, protection);
4967 if (filebuf_open(fstream_rdbuf(this), name, mode|OPENMODE_out, protection) == NULL)
4968 ios_clear(base, base->state | IOSTATE_failbit);
4971 /* ?setbuf@fstream@@QAEPAVstreambuf@@PADH@Z */
4972 /* ?setbuf@fstream@@QEAAPEAVstreambuf@@PEADH@Z */
4973 DEFINE_THISCALL_WRAPPER(fstream_setbuf, 12)
4974 streambuf* __thiscall fstream_setbuf(iostream *this, char *buffer, int length)
4976 ios *base = istream_get_ios(&this->base1);
4977 filebuf* fb = fstream_rdbuf(this);
4979 TRACE("(%p %p %d)\n", this, buffer, length);
4981 if (filebuf_is_open(fb)) {
4982 ios_clear(base, base->state | IOSTATE_failbit);
4983 return NULL;
4986 return filebuf_setbuf(fb, buffer, length);
4989 /* ?setmode@fstream@@QAEHH@Z */
4990 /* ?setmode@fstream@@QEAAHH@Z */
4991 DEFINE_THISCALL_WRAPPER(fstream_setmode, 8)
4992 int __thiscall fstream_setmode(iostream *this, int mode)
4994 TRACE("(%p %d)\n", this, mode);
4995 return filebuf_setmode(fstream_rdbuf(this), mode);
4998 /* ??0Iostream_init@@QAE@AAVios@@H@Z */
4999 /* ??0Iostream_init@@QEAA@AEAVios@@H@Z */
5000 DEFINE_THISCALL_WRAPPER(Iostream_init_ios_ctor, 12)
5001 void* __thiscall Iostream_init_ios_ctor(void *this, ios *obj, int n)
5003 TRACE("(%p %p %d)\n", this, obj, n);
5004 obj->delbuf = 1;
5005 if (n >= 0) {
5006 obj->tie = &cout.os;
5007 if (n > 0)
5008 ios_setf(obj, FLAGS_unitbuf);
5010 return this;
5013 /* ??0Iostream_init@@QAE@XZ */
5014 /* ??0Iostream_init@@QEAA@XZ */
5015 DEFINE_THISCALL_WRAPPER(Iostream_init_ctor, 4)
5016 void* __thiscall Iostream_init_ctor(void *this)
5018 TRACE("(%p)\n", this);
5019 return this;
5022 /* ??1Iostream_init@@QAE@XZ */
5023 /* ??1Iostream_init@@QEAA@XZ */
5024 DEFINE_THISCALL_WRAPPER(Iostream_init_dtor, 4)
5025 void __thiscall Iostream_init_dtor(void *this)
5027 TRACE("(%p)\n", this);
5030 /* ??4Iostream_init@@QAEAAV0@ABV0@@Z */
5031 /* ??4Iostream_init@@QEAAAEAV0@AEBV0@@Z */
5032 DEFINE_THISCALL_WRAPPER(Iostream_init_assign, 8)
5033 void* __thiscall Iostream_init_assign(void *this, const void *rhs)
5035 TRACE("(%p %p)\n", this, rhs);
5036 return this;
5039 /* ?sync_with_stdio@ios@@SAXXZ */
5040 void __cdecl ios_sync_with_stdio(void)
5042 if (!ios_sunk_with_stdio) {
5043 stdiobuf *new_buf;
5045 TRACE("()\n");
5047 /* run at most once */
5048 ios_sunk_with_stdio++;
5050 /* calls to [io]stream_assign_sb automatically destroy the old buffers */
5051 if ((new_buf = MSVCRT_operator_new(sizeof(stdiobuf)))) {
5052 stdiobuf_file_ctor(new_buf, stdin);
5053 istream_assign_sb(&cin.is, &new_buf->base);
5054 } else
5055 istream_assign_sb(&cin.is, NULL);
5056 cin.vbase.delbuf = 1;
5057 ios_setf(&cin.vbase, FLAGS_stdio);
5059 if ((new_buf = MSVCRT_operator_new(sizeof(stdiobuf)))) {
5060 stdiobuf_file_ctor(new_buf, stdout);
5061 stdiobuf_setrwbuf(new_buf, 0, 80);
5062 ostream_assign_sb(&cout.os, &new_buf->base);
5063 } else
5064 ostream_assign_sb(&cout.os, NULL);
5065 cout.vbase.delbuf = 1;
5066 ios_setf(&cout.vbase, FLAGS_unitbuf | FLAGS_stdio);
5068 if ((new_buf = MSVCRT_operator_new(sizeof(stdiobuf)))) {
5069 stdiobuf_file_ctor(new_buf, stderr);
5070 stdiobuf_setrwbuf(new_buf, 0, 80);
5071 ostream_assign_sb(&cerr.os, &new_buf->base);
5072 } else
5073 ostream_assign_sb(&cerr.os, NULL);
5074 cerr.vbase.delbuf = 1;
5075 ios_setf(&cerr.vbase, FLAGS_unitbuf | FLAGS_stdio);
5077 if ((new_buf = MSVCRT_operator_new(sizeof(stdiobuf)))) {
5078 stdiobuf_file_ctor(new_buf, stderr);
5079 stdiobuf_setrwbuf(new_buf, 0, 512);
5080 ostream_assign_sb(&MSVCP_clog.os, &new_buf->base);
5081 } else
5082 ostream_assign_sb(&MSVCP_clog.os, NULL);
5083 MSVCP_clog.vbase.delbuf = 1;
5084 ios_setf(&MSVCP_clog.vbase, FLAGS_stdio);
5089 #ifdef __ASM_USE_THISCALL_WRAPPER
5091 #define DEFINE_VTBL_WRAPPER(off) \
5092 __ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
5093 "popl %eax\n\t" \
5094 "popl %ecx\n\t" \
5095 "pushl %eax\n\t" \
5096 "movl 0(%ecx), %eax\n\t" \
5097 "jmp *" #off "(%eax)\n\t")
5099 DEFINE_VTBL_WRAPPER(0);
5100 DEFINE_VTBL_WRAPPER(4);
5101 DEFINE_VTBL_WRAPPER(8);
5102 DEFINE_VTBL_WRAPPER(12);
5103 DEFINE_VTBL_WRAPPER(16);
5104 DEFINE_VTBL_WRAPPER(20);
5105 DEFINE_VTBL_WRAPPER(24);
5106 DEFINE_VTBL_WRAPPER(28);
5107 DEFINE_VTBL_WRAPPER(32);
5108 DEFINE_VTBL_WRAPPER(36);
5109 DEFINE_VTBL_WRAPPER(40);
5110 DEFINE_VTBL_WRAPPER(44);
5111 DEFINE_VTBL_WRAPPER(48);
5112 DEFINE_VTBL_WRAPPER(52);
5113 DEFINE_VTBL_WRAPPER(56);
5115 #endif
5117 void* (__cdecl *MSVCRT_operator_new)(SIZE_T);
5118 void (__cdecl *MSVCRT_operator_delete)(void*);
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 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
5139 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
5141 else
5143 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
5144 MSVCRT_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 = MSVCRT_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 = MSVCRT_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 = MSVCRT_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 = MSVCRT_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;