msvcirt: Add implementation of streambuf::pbackfail.
[wine.git] / dlls / msvcirt / msvcirt.c
blob70e92e7a79c8062f2a65c6a96d685ada25769170
1 /*
2 * Copyright (C) 2007 Alexandre Julliard
3 * Copyright (C) 2015 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
20 #include "config.h"
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "msvcirt.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcirt);
32 #define RESERVE_SIZE 512
34 /* class streambuf */
35 typedef struct {
36 const vtable_ptr *vtable;
37 int allocated;
38 int unbuffered;
39 int stored_char;
40 char *base;
41 char *ebuf;
42 char *pbase;
43 char *pptr;
44 char *epptr;
45 char *eback;
46 char *gptr;
47 char *egptr;
48 int do_lock;
49 CRITICAL_SECTION lock;
50 } streambuf;
52 void __thiscall streambuf_setb(streambuf*, char*, char*, int);
53 streambuf* __thiscall streambuf_setbuf(streambuf*, char*, int);
54 void __thiscall streambuf_setg(streambuf*, char*, char*, char*);
55 void __thiscall streambuf_setp(streambuf*, char*, char*);
57 typedef struct {
58 LPVOID VTable;
59 } class_ios;
61 typedef struct {
62 LPVOID VTable;
63 } class_ostream;
65 typedef struct {
66 LPVOID VTable;
67 } class_strstreambuf;
69 /* ??_7streambuf@@6B@ */
70 extern const vtable_ptr MSVCP_streambuf_vtable;
72 #ifndef __GNUC__
73 void __asm_dummy_vtables(void) {
74 #endif
75 __ASM_VTABLE(streambuf,
76 VTABLE_ADD_FUNC(streambuf_vector_dtor)
77 VTABLE_ADD_FUNC(streambuf_sync)
78 VTABLE_ADD_FUNC(streambuf_setbuf)
79 VTABLE_ADD_FUNC(streambuf_seekoff)
80 VTABLE_ADD_FUNC(streambuf_seekpos)
81 VTABLE_ADD_FUNC(streambuf_xsputn)
82 VTABLE_ADD_FUNC(streambuf_xsgetn)
83 VTABLE_ADD_FUNC(streambuf_overflow)
84 VTABLE_ADD_FUNC(streambuf_underflow)
85 VTABLE_ADD_FUNC(streambuf_pbackfail)
86 VTABLE_ADD_FUNC(streambuf_doallocate));
87 #ifndef __GNUC__
89 #endif
91 DEFINE_RTTI_DATA0(streambuf, 0, ".?AVstreambuf@@")
93 /* ??0streambuf@@IAE@PADH@Z */
94 /* ??0streambuf@@IEAA@PEADH@Z */
95 DEFINE_THISCALL_WRAPPER(streambuf_reserve_ctor, 12)
96 streambuf* __thiscall streambuf_reserve_ctor(streambuf *this, char *buffer, int length)
98 TRACE("(%p %p %d)\n", this, buffer, length);
99 this->vtable = &MSVCP_streambuf_vtable;
100 this->allocated = 0;
101 this->stored_char = EOF;
102 this->do_lock = -1;
103 this->base = NULL;
104 streambuf_setbuf(this, buffer, length);
105 streambuf_setg(this, NULL, NULL, NULL);
106 streambuf_setp(this, NULL, NULL);
107 InitializeCriticalSection(&this->lock);
108 return this;
111 /* ??0streambuf@@IAE@XZ */
112 /* ??0streambuf@@IEAA@XZ */
113 DEFINE_THISCALL_WRAPPER(streambuf_ctor, 4)
114 streambuf* __thiscall streambuf_ctor(streambuf *this)
116 streambuf_reserve_ctor(this, NULL, 0);
117 this->unbuffered = 0;
118 return this;
121 /* ??0streambuf@@QAE@ABV0@@Z */
122 /* ??0streambuf@@QEAA@AEBV0@@Z */
123 DEFINE_THISCALL_WRAPPER(streambuf_copy_ctor, 8)
124 streambuf* __thiscall streambuf_copy_ctor(streambuf *this, const streambuf *copy)
126 TRACE("(%p %p)\n", this, copy);
127 *this = *copy;
128 this->vtable = &MSVCP_streambuf_vtable;
129 return this;
132 /* ??1streambuf@@UAE@XZ */
133 /* ??1streambuf@@UEAA@XZ */
134 DEFINE_THISCALL_WRAPPER(streambuf_dtor, 4)
135 void __thiscall streambuf_dtor(streambuf *this)
137 TRACE("(%p)\n", this);
138 if (this->allocated)
139 MSVCRT_operator_delete(this->base);
140 DeleteCriticalSection(&this->lock);
143 /* ??4streambuf@@QAEAAV0@ABV0@@Z */
144 /* ??4streambuf@@QEAAAEAV0@AEBV0@@Z */
145 DEFINE_THISCALL_WRAPPER(streambuf_assign, 8)
146 streambuf* __thiscall streambuf_assign(streambuf *this, const streambuf *rhs)
148 streambuf_dtor(this);
149 return streambuf_copy_ctor(this, rhs);
152 /* ??_Estreambuf@@UAEPAXI@Z */
153 DEFINE_THISCALL_WRAPPER(streambuf_vector_dtor, 8)
154 streambuf* __thiscall streambuf_vector_dtor(streambuf *this, unsigned int flags)
156 TRACE("(%p %x)\n", this, flags);
157 if (flags & 2) {
158 /* we have an array, with the number of elements stored before the first object */
159 INT_PTR i, *ptr = (INT_PTR *)this-1;
161 for (i = *ptr-1; i >= 0; i--)
162 streambuf_dtor(this+i);
163 MSVCRT_operator_delete(ptr);
164 } else {
165 streambuf_dtor(this);
166 if (flags & 1)
167 MSVCRT_operator_delete(this);
169 return this;
172 /* ??_Gstreambuf@@UAEPAXI@Z */
173 DEFINE_THISCALL_WRAPPER(streambuf_scalar_dtor, 8)
174 streambuf* __thiscall streambuf_scalar_dtor(streambuf *this, unsigned int flags)
176 TRACE("(%p %x)\n", this, flags);
177 streambuf_dtor(this);
178 if (flags & 1) MSVCRT_operator_delete(this);
179 return this;
182 /* ?doallocate@streambuf@@MAEHXZ */
183 /* ?doallocate@streambuf@@MEAAHXZ */
184 DEFINE_THISCALL_WRAPPER(streambuf_doallocate, 4)
185 #define call_streambuf_doallocate(this) CALL_VTBL_FUNC(this, 40, int, (streambuf*), (this))
186 int __thiscall streambuf_doallocate(streambuf *this)
188 char *reserve;
190 TRACE("(%p)\n", this);
191 reserve = MSVCRT_operator_new(RESERVE_SIZE);
192 if (!reserve)
193 return EOF;
195 streambuf_setb(this, reserve, reserve + RESERVE_SIZE, 1);
196 return 1;
199 /* ?allocate@streambuf@@IAEHXZ */
200 /* ?allocate@streambuf@@IEAAHXZ */
201 DEFINE_THISCALL_WRAPPER(streambuf_allocate, 4)
202 int __thiscall streambuf_allocate(streambuf *this)
204 TRACE("(%p)\n", this);
205 if (this->base != NULL || this->unbuffered)
206 return 0;
207 return call_streambuf_doallocate(this);
210 /* ?base@streambuf@@IBEPADXZ */
211 /* ?base@streambuf@@IEBAPEADXZ */
212 DEFINE_THISCALL_WRAPPER(streambuf_base, 4)
213 char* __thiscall streambuf_base(const streambuf *this)
215 TRACE("(%p)\n", this);
216 return this->base;
219 /* ?blen@streambuf@@IBEHXZ */
220 /* ?blen@streambuf@@IEBAHXZ */
221 DEFINE_THISCALL_WRAPPER(streambuf_blen, 4)
222 int __thiscall streambuf_blen(const streambuf *this)
224 TRACE("(%p)\n", this);
225 return this->ebuf - this->base;
228 /* ?eback@streambuf@@IBEPADXZ */
229 /* ?eback@streambuf@@IEBAPEADXZ */
230 DEFINE_THISCALL_WRAPPER(streambuf_eback, 4)
231 char* __thiscall streambuf_eback(const streambuf *this)
233 TRACE("(%p)\n", this);
234 return this->eback;
237 /* ?ebuf@streambuf@@IBEPADXZ */
238 /* ?ebuf@streambuf@@IEBAPEADXZ */
239 DEFINE_THISCALL_WRAPPER(streambuf_ebuf, 4)
240 char* __thiscall streambuf_ebuf(const streambuf *this)
242 TRACE("(%p)\n", this);
243 return this->ebuf;
246 /* ?egptr@streambuf@@IBEPADXZ */
247 /* ?egptr@streambuf@@IEBAPEADXZ */
248 DEFINE_THISCALL_WRAPPER(streambuf_egptr, 4)
249 char* __thiscall streambuf_egptr(const streambuf *this)
251 TRACE("(%p)\n", this);
252 return this->egptr;
255 /* ?epptr@streambuf@@IBEPADXZ */
256 /* ?epptr@streambuf@@IEBAPEADXZ */
257 DEFINE_THISCALL_WRAPPER(streambuf_epptr, 4)
258 char* __thiscall streambuf_epptr(const streambuf *this)
260 TRACE("(%p)\n", this);
261 return this->epptr;
264 /* ?gptr@streambuf@@IBEPADXZ */
265 /* ?gptr@streambuf@@IEBAPEADXZ */
266 DEFINE_THISCALL_WRAPPER(streambuf_gptr, 4)
267 char* __thiscall streambuf_gptr(const streambuf *this)
269 TRACE("(%p)\n", this);
270 return this->gptr;
273 /* ?pbase@streambuf@@IBEPADXZ */
274 /* ?pbase@streambuf@@IEBAPEADXZ */
275 DEFINE_THISCALL_WRAPPER(streambuf_pbase, 4)
276 char* __thiscall streambuf_pbase(const streambuf *this)
278 TRACE("(%p)\n", this);
279 return this->pbase;
282 /* ?pptr@streambuf@@IBEPADXZ */
283 /* ?pptr@streambuf@@IEBAPEADXZ */
284 DEFINE_THISCALL_WRAPPER(streambuf_pptr, 4)
285 char* __thiscall streambuf_pptr(const streambuf *this)
287 TRACE("(%p)\n", this);
288 return this->pptr;
291 /* ?clrlock@streambuf@@QAEXXZ */
292 /* ?clrlock@streambuf@@QEAAXXZ */
293 DEFINE_THISCALL_WRAPPER(streambuf_clrlock, 4)
294 void __thiscall streambuf_clrlock(streambuf *this)
296 TRACE("(%p)\n", this);
297 if (this->do_lock <= 0)
298 this->do_lock++;
301 /* ?lock@streambuf@@QAEXXZ */
302 /* ?lock@streambuf@@QEAAXXZ */
303 DEFINE_THISCALL_WRAPPER(streambuf_lock, 4)
304 void __thiscall streambuf_lock(streambuf *this)
306 TRACE("(%p)\n", this);
307 if (this->do_lock < 0)
308 EnterCriticalSection(&this->lock);
311 /* ?lockptr@streambuf@@IAEPAU_CRT_CRITICAL_SECTION@@XZ */
312 /* ?lockptr@streambuf@@IEAAPEAU_CRT_CRITICAL_SECTION@@XZ */
313 DEFINE_THISCALL_WRAPPER(streambuf_lockptr, 4)
314 CRITICAL_SECTION* __thiscall streambuf_lockptr(streambuf *this)
316 TRACE("(%p)\n", this);
317 return &this->lock;
320 /* ?gbump@streambuf@@IAEXH@Z */
321 /* ?gbump@streambuf@@IEAAXH@Z */
322 DEFINE_THISCALL_WRAPPER(streambuf_gbump, 8)
323 void __thiscall streambuf_gbump(streambuf *this, int count)
325 TRACE("(%p %d)\n", this, count);
326 this->gptr += count;
329 /* ?pbump@streambuf@@IAEXH@Z */
330 /* ?pbump@streambuf@@IEAAXH@Z */
331 DEFINE_THISCALL_WRAPPER(streambuf_pbump, 8)
332 void __thiscall streambuf_pbump(streambuf *this, int count)
334 TRACE("(%p %d)\n", this, count);
335 this->pptr += count;
338 /* ?in_avail@streambuf@@QBEHXZ */
339 /* ?in_avail@streambuf@@QEBAHXZ */
340 DEFINE_THISCALL_WRAPPER(streambuf_in_avail, 4)
341 int __thiscall streambuf_in_avail(const streambuf *this)
343 TRACE("(%p)\n", this);
344 return this->egptr - this->gptr;
347 /* ?out_waiting@streambuf@@QBEHXZ */
348 /* ?out_waiting@streambuf@@QEBAHXZ */
349 DEFINE_THISCALL_WRAPPER(streambuf_out_waiting, 4)
350 int __thiscall streambuf_out_waiting(const streambuf *this)
352 TRACE("(%p)\n", this);
353 return this->pptr - this->pbase;
356 /* Unexported */
357 DEFINE_THISCALL_WRAPPER(streambuf_overflow, 8)
358 #define call_streambuf_overflow(this, c) CALL_VTBL_FUNC(this, 28, int, (streambuf*, int), (this, c))
359 int __thiscall streambuf_overflow(streambuf *this, int c)
361 ERR("overflow is not implemented in streambuf\n");
362 return EOF;
365 /* ?pbackfail@streambuf@@UAEHH@Z */
366 /* ?pbackfail@streambuf@@UEAAHH@Z */
367 DEFINE_THISCALL_WRAPPER(streambuf_pbackfail, 8)
368 int __thiscall streambuf_pbackfail(streambuf *this, int c)
370 TRACE("(%p %d)\n", this, c);
371 if (this->gptr <= this->eback)
372 return EOF;
373 return *--this->gptr = c;
376 /* ?seekoff@streambuf@@UAEJJW4seek_dir@ios@@H@Z */
377 /* ?seekoff@streambuf@@UEAAJJW4seek_dir@ios@@H@Z */
378 DEFINE_THISCALL_WRAPPER(streambuf_seekoff, 16)
379 #define call_streambuf_seekoff(this, off, dir, mode) CALL_VTBL_FUNC(this, 12, streampos, (streambuf*, streamoff, ios_seek_dir, int), (this, off, dir, mode))
380 streampos __thiscall streambuf_seekoff(streambuf *this, streamoff offset, ios_seek_dir dir, int mode)
382 TRACE("(%p %d %d %d)\n", this, offset, dir, mode);
383 return EOF;
386 /* ?seekpos@streambuf@@UAEJJH@Z */
387 /* ?seekpos@streambuf@@UEAAJJH@Z */
388 DEFINE_THISCALL_WRAPPER(streambuf_seekpos, 12)
389 streampos __thiscall streambuf_seekpos(streambuf *this, streampos pos, int mode)
391 TRACE("(%p %d %d)\n", this, pos, mode);
392 return call_streambuf_seekoff(this, pos, SEEKDIR_beg, mode);
395 /* ?setb@streambuf@@IAEXPAD0H@Z */
396 /* ?setb@streambuf@@IEAAXPEAD0H@Z */
397 DEFINE_THISCALL_WRAPPER(streambuf_setb, 16)
398 void __thiscall streambuf_setb(streambuf *this, char *ba, char *eb, int delete)
400 TRACE("(%p %p %p %d)\n", this, ba, eb, delete);
401 if (this->allocated)
402 MSVCRT_operator_delete(this->base);
403 this->allocated = delete;
404 this->base = ba;
405 this->ebuf = eb;
408 /* ?setbuf@streambuf@@UAEPAV1@PADH@Z */
409 /* ?setbuf@streambuf@@UEAAPEAV1@PEADH@Z */
410 DEFINE_THISCALL_WRAPPER(streambuf_setbuf, 12)
411 streambuf* __thiscall streambuf_setbuf(streambuf *this, char *buffer, int length)
413 TRACE("(%p %p %d)\n", this, buffer, length);
414 if (this->base != NULL)
415 return NULL;
417 if (buffer == NULL || !length) {
418 this->unbuffered = 1;
419 this->base = this->ebuf = NULL;
420 } else {
421 this->unbuffered = 0;
422 this->base = buffer;
423 this->ebuf = buffer + length;
425 return this;
428 /* ?setg@streambuf@@IAEXPAD00@Z */
429 /* ?setg@streambuf@@IEAAXPEAD00@Z */
430 DEFINE_THISCALL_WRAPPER(streambuf_setg, 16)
431 void __thiscall streambuf_setg(streambuf *this, char *ek, char *gp, char *eg)
433 TRACE("(%p %p %p %p)\n", this, ek, gp, eg);
434 this->eback = ek;
435 this->gptr = gp;
436 this->egptr = eg;
439 /* ?setlock@streambuf@@QAEXXZ */
440 /* ?setlock@streambuf@@QEAAXXZ */
441 DEFINE_THISCALL_WRAPPER(streambuf_setlock, 4)
442 void __thiscall streambuf_setlock(streambuf *this)
444 TRACE("(%p)\n", this);
445 this->do_lock--;
448 /* ?setp@streambuf@@IAEXPAD0@Z */
449 /* ?setp@streambuf@@IEAAXPEAD0@Z */
450 DEFINE_THISCALL_WRAPPER(streambuf_setp, 12)
451 void __thiscall streambuf_setp(streambuf *this, char *pb, char *ep)
453 TRACE("(%p %p %p)\n", this, pb, ep);
454 this->pbase = this->pptr = pb;
455 this->epptr = ep;
458 /* ?sync@streambuf@@UAEHXZ */
459 /* ?sync@streambuf@@UEAAHXZ */
460 DEFINE_THISCALL_WRAPPER(streambuf_sync, 4)
461 int __thiscall streambuf_sync(streambuf *this)
463 TRACE("(%p)\n", this);
464 return (this->gptr >= this->egptr && this->pbase >= this->pptr) ? 0 : EOF;
467 /* ?unbuffered@streambuf@@IAEXH@Z */
468 /* ?unbuffered@streambuf@@IEAAXH@Z */
469 DEFINE_THISCALL_WRAPPER(streambuf_unbuffered_set, 8)
470 void __thiscall streambuf_unbuffered_set(streambuf *this, int buf)
472 TRACE("(%p %d)\n", this, buf);
473 this->unbuffered = buf;
476 /* ?unbuffered@streambuf@@IBEHXZ */
477 /* ?unbuffered@streambuf@@IEBAHXZ */
478 DEFINE_THISCALL_WRAPPER(streambuf_unbuffered_get, 4)
479 int __thiscall streambuf_unbuffered_get(const streambuf *this)
481 TRACE("(%p)\n", this);
482 return this->unbuffered;
485 /* Unexported */
486 DEFINE_THISCALL_WRAPPER(streambuf_underflow, 4)
487 #define call_streambuf_underflow(this) CALL_VTBL_FUNC(this, 32, int, (streambuf*), (this))
488 int __thiscall streambuf_underflow(streambuf *this)
490 ERR("underflow is not implemented in streambuf\n");
491 return EOF;
494 /* ?unlock@streambuf@@QAEXXZ */
495 /* ?unlock@streambuf@@QEAAXXZ */
496 DEFINE_THISCALL_WRAPPER(streambuf_unlock, 4)
497 void __thiscall streambuf_unlock(streambuf *this)
499 TRACE("(%p)\n", this);
500 if (this->do_lock < 0)
501 LeaveCriticalSection(&this->lock);
504 /* ?xsgetn@streambuf@@UAEHPADH@Z */
505 /* ?xsgetn@streambuf@@UEAAHPEADH@Z */
506 DEFINE_THISCALL_WRAPPER(streambuf_xsgetn, 12)
507 #define call_streambuf_xsgetn(this, buffer, count) CALL_VTBL_FUNC(this, 24, int, (streambuf*, char*, int), (this, buffer, count))
508 int __thiscall streambuf_xsgetn(streambuf *this, char *buffer, int count)
510 int copied = 0, chunk;
512 TRACE("(%p %p %d)\n", this, buffer, count);
514 if (this->unbuffered) {
515 if (this->stored_char == EOF)
516 this->stored_char = call_streambuf_underflow(this);
517 while (copied < count && this->stored_char != EOF) {
518 buffer[copied++] = this->stored_char;
519 this->stored_char = call_streambuf_underflow(this);
521 } else {
522 while (copied < count) {
523 if (call_streambuf_underflow(this) == EOF)
524 break;
525 chunk = this->egptr - this->gptr;
526 if (chunk > count - copied)
527 chunk = count - copied;
528 memcpy(buffer+copied, this->gptr, chunk);
529 this->gptr += chunk;
530 copied += chunk;
533 return copied;
536 /* ?xsputn@streambuf@@UAEHPBDH@Z */
537 /* ?xsputn@streambuf@@UEAAHPEBDH@Z */
538 DEFINE_THISCALL_WRAPPER(streambuf_xsputn, 12)
539 #define call_streambuf_xsputn(this, data, length) CALL_VTBL_FUNC(this, 20, int, (streambuf*, const char*, int), (this, data, length))
540 int __thiscall streambuf_xsputn(streambuf *this, const char *data, int length)
542 int copied = 0, chunk;
544 TRACE("(%p %p %d)\n", this, data, length);
546 while (copied < length) {
547 if (this->unbuffered || this->pptr == this->epptr) {
548 if (call_streambuf_overflow(this, data[copied]) == EOF)
549 break;
550 copied++;
551 } else {
552 chunk = this->epptr - this->pptr;
553 if (chunk > length - copied)
554 chunk = length - copied;
555 memcpy(this->pptr, data+copied, chunk);
556 this->pptr += chunk;
557 copied += chunk;
560 return copied;
563 /* ?sgetc@streambuf@@QAEHXZ */
564 /* ?sgetc@streambuf@@QEAAHXZ */
565 DEFINE_THISCALL_WRAPPER(streambuf_sgetc, 4)
566 int __thiscall streambuf_sgetc(streambuf *this)
568 TRACE("(%p)\n", this);
569 if (this->unbuffered) {
570 if (this->stored_char == EOF)
571 this->stored_char = call_streambuf_underflow(this);
572 return this->stored_char;
573 } else
574 return call_streambuf_underflow(this);
577 /* ?sputc@streambuf@@QAEHH@Z */
578 /* ?sputc@streambuf@@QEAAHH@Z */
579 DEFINE_THISCALL_WRAPPER(streambuf_sputc, 8)
580 int __thiscall streambuf_sputc(streambuf *this, int ch)
582 TRACE("(%p %d)\n", this, ch);
583 return (this->pptr < this->epptr) ? *this->pptr++ = ch : call_streambuf_overflow(this, ch);
586 /* ?sgetn@streambuf@@QAEHPADH@Z */
587 /* ?sgetn@streambuf@@QEAAHPEADH@Z */
588 DEFINE_THISCALL_WRAPPER(streambuf_sgetn, 12)
589 int __thiscall streambuf_sgetn(streambuf *this, char *buffer, int count)
591 return call_streambuf_xsgetn(this, buffer, count);
594 /* ?sputn@streambuf@@QAEHPBDH@Z */
595 /* ?sputn@streambuf@@QEAAHPEBDH@Z */
596 DEFINE_THISCALL_WRAPPER(streambuf_sputn, 12)
597 int __thiscall streambuf_sputn(streambuf *this, const char *data, int length)
599 return call_streambuf_xsputn(this, data, length);
602 /* ?snextc@streambuf@@QAEHXZ */
603 /* ?snextc@streambuf@@QEAAHXZ */
604 DEFINE_THISCALL_WRAPPER(streambuf_snextc, 4)
605 int __thiscall streambuf_snextc(streambuf *this)
607 TRACE("(%p)\n", this);
608 if (this->unbuffered) {
609 if (this->stored_char == EOF)
610 call_streambuf_underflow(this);
611 return this->stored_char = call_streambuf_underflow(this);
612 } else {
613 if (this->gptr >= this->egptr)
614 call_streambuf_underflow(this);
615 this->gptr++;
616 return (this->gptr < this->egptr) ? *this->gptr : call_streambuf_underflow(this);
620 /* ?sbumpc@streambuf@@QAEHXZ */
621 /* ?sbumpc@streambuf@@QEAAHXZ */
622 DEFINE_THISCALL_WRAPPER(streambuf_sbumpc, 4)
623 int __thiscall streambuf_sbumpc(streambuf *this)
625 int ret;
627 TRACE("(%p)\n", this);
629 if (this->unbuffered) {
630 ret = this->stored_char;
631 this->stored_char = EOF;
632 if (ret == EOF)
633 ret = call_streambuf_underflow(this);
634 } else {
635 ret = (this->gptr < this->egptr) ? *this->gptr : call_streambuf_underflow(this);
636 this->gptr++;
638 return ret;
641 /* ?stossc@streambuf@@QAEXXZ */
642 /* ?stossc@streambuf@@QEAAXXZ */
643 DEFINE_THISCALL_WRAPPER(streambuf_stossc, 4)
644 void __thiscall streambuf_stossc(streambuf *this)
646 TRACE("(%p)\n", this);
647 if (this->unbuffered) {
648 if (this->stored_char == EOF)
649 call_streambuf_underflow(this);
650 else
651 this->stored_char = EOF;
652 } else {
653 if (this->gptr >= this->egptr)
654 call_streambuf_underflow(this);
655 if (this->gptr < this->egptr)
656 this->gptr++;
660 /******************************************************************
661 * ??1ios@@UAE@XZ (MSVCRTI.@)
662 * class ios & __thiscall ios::-ios<<(void)
664 DEFINE_THISCALL_WRAPPER(MSVCIRT_ios_sl_void,4)
665 void * __thiscall MSVCIRT_ios_sl_void(class_ios * _this)
667 FIXME("(%p) stub\n", _this);
668 return _this;
671 /******************************************************************
672 * ??0ostrstream@@QAE@XZ (MSVCRTI.@)
673 * class ostream & __thiscall ostrstream::ostrstream<<(void)
675 DEFINE_THISCALL_WRAPPER(MSVCIRT_ostrstream_sl_void,4)
676 void * __thiscall MSVCIRT_ostrstream_sl_void(class_ostream * _this)
678 FIXME("(%p) stub\n", _this);
679 return _this;
682 /******************************************************************
683 * ??6ostream@@QAEAAV0@E@Z (MSVCRTI.@)
684 * class ostream & __thiscall ostream::operator<<(unsigned char)
686 DEFINE_THISCALL_WRAPPER(MSVCIRT_operator_sl_uchar,8)
687 void * __thiscall MSVCIRT_operator_sl_uchar(class_ostream * _this, unsigned char ch)
689 FIXME("(%p)->(%c) stub\n", _this, ch);
690 return _this;
693 /******************************************************************
694 * ??6ostream@@QAEAAV0@H@Z (MSVCRTI.@)
695 * class ostream & __thiscall ostream::operator<<(int)
697 DEFINE_THISCALL_WRAPPER(MSVCIRT_operator_sl_int,8)
698 void * __thiscall MSVCIRT_operator_sl_int(class_ostream * _this, int integer)
700 FIXME("(%p)->(%d) stub\n", _this, integer);
701 return _this;
704 /******************************************************************
705 * ??6ostream@@QAEAAV0@PBD@Z (MSVCRTI.@)
706 * class ostream & __thiscall ostream::operator<<(char const *)
708 DEFINE_THISCALL_WRAPPER(MSVCIRT_operator_sl_pchar,8)
709 void * __thiscall MSVCIRT_operator_sl_pchar(class_ostream * _this, const char * string)
711 FIXME("(%p)->(%s) stub\n", _this, debugstr_a(string));
712 return _this;
715 /******************************************************************
716 * ??6ostream@@QAEAAV0@P6AAAV0@AAV0@@Z@Z (MSVCRTI.@)
717 * class ostream & __thiscall ostream::operator<<(class ostream & (__cdecl*)(class ostream &))
719 DEFINE_THISCALL_WRAPPER(MSVCIRT_operator_sl_callback,8)
720 void * __thiscall MSVCIRT_operator_sl_callback(class_ostream * _this, class_ostream * (__cdecl*func)(class_ostream*))
722 TRACE("%p, %p\n", _this, func);
723 return func(_this);
726 /******************************************************************
727 * ?endl@@YAAAVostream@@AAV1@@Z (MSVCRTI.@)
728 * class ostream & __cdecl endl(class ostream &)
730 void * CDECL MSVCIRT_endl(class_ostream * _this)
732 FIXME("(%p)->() stub\n", _this);
733 return _this;
736 /******************************************************************
737 * ?ends@@YAAAVostream@@AAV1@@Z (MSVCRTI.@)
738 * class ostream & __cdecl ends(class ostream &)
740 void * CDECL MSVCIRT_ends(class_ostream * _this)
742 FIXME("(%p)->() stub\n", _this);
743 return _this;
746 /******************************************************************
747 * ?str@strstreambuf@@QAEPADXZ (MSVCRTI.@)
748 * class strstreambuf & __thiscall strstreambuf::str(class strstreambuf &)
750 DEFINE_THISCALL_WRAPPER(MSVCIRT_str_sl_void,4)
751 char * __thiscall MSVCIRT_str_sl_void(class_strstreambuf * _this)
753 FIXME("(%p)->() stub\n", _this);
754 return 0;
757 #ifdef __i386__
759 #define DEFINE_VTBL_WRAPPER(off) \
760 __ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
761 "popl %eax\n\t" \
762 "popl %ecx\n\t" \
763 "pushl %eax\n\t" \
764 "movl 0(%ecx), %eax\n\t" \
765 "jmp *" #off "(%eax)\n\t")
767 DEFINE_VTBL_WRAPPER(0);
768 DEFINE_VTBL_WRAPPER(4);
769 DEFINE_VTBL_WRAPPER(8);
770 DEFINE_VTBL_WRAPPER(12);
771 DEFINE_VTBL_WRAPPER(16);
772 DEFINE_VTBL_WRAPPER(20);
773 DEFINE_VTBL_WRAPPER(24);
774 DEFINE_VTBL_WRAPPER(28);
775 DEFINE_VTBL_WRAPPER(32);
776 DEFINE_VTBL_WRAPPER(36);
777 DEFINE_VTBL_WRAPPER(40);
778 DEFINE_VTBL_WRAPPER(44);
779 DEFINE_VTBL_WRAPPER(48);
780 DEFINE_VTBL_WRAPPER(52);
781 DEFINE_VTBL_WRAPPER(56);
783 #endif
785 void* (__cdecl *MSVCRT_operator_new)(SIZE_T);
786 void (__cdecl *MSVCRT_operator_delete)(void*);
788 static void init_cxx_funcs(void)
790 HMODULE hmod = GetModuleHandleA("msvcrt.dll");
792 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
794 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
795 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
797 else
799 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
800 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
804 static void init_io(void *base)
806 #ifdef __x86_64__
807 init_streambuf_rtti(base);
808 #endif
811 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
813 switch (reason)
815 case DLL_WINE_PREATTACH:
816 return FALSE; /* prefer native version */
817 case DLL_PROCESS_ATTACH:
818 init_cxx_funcs();
819 init_exception(inst);
820 init_io(inst);
821 DisableThreadLibraryCalls( inst );
822 break;
824 return TRUE;