From c4a5730ec3eb79c0ab341c5dc001a1b104b56a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Matellanes?= Date: Tue, 14 Jun 2016 15:40:21 +0100 Subject: [PATCH] msvcirt: Implement ostream::write. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Iván Matellanes Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcirt/msvcirt.c | 16 +++++++++++----- dlls/msvcirt/tests/msvcirt.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 75c5a9d1d39..9cb7a5ceca0 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -2506,7 +2506,15 @@ streampos __thiscall ostream_tellp(ostream *this) DEFINE_THISCALL_WRAPPER(ostream_write_char, 12) ostream* __thiscall ostream_write_char(ostream *this, const char *str, int count) { - FIXME("(%p %s %d) stub\n", this, str, count); + ios *base = ostream_get_ios(this); + + TRACE("(%p %p %d)\n", this, str, count); + + if (ostream_opfx(this)) { + if (streambuf_sputn(base->sb, str, count) != count) + base->state = IOSTATE_badbit | IOSTATE_failbit; + ostream_osfx(this); + } return this; } @@ -2515,8 +2523,7 @@ ostream* __thiscall ostream_write_char(ostream *this, const char *str, int count DEFINE_THISCALL_WRAPPER(ostream_write_signed_char, 12) ostream* __thiscall ostream_write_signed_char(ostream *this, const signed char *str, int count) { - FIXME("(%p %s %d) stub\n", this, str, count); - return this; + return ostream_write_char(this, (const char*) str, count); } /* ?write@ostream@@QAEAAV1@PBEH@Z */ @@ -2524,8 +2531,7 @@ ostream* __thiscall ostream_write_signed_char(ostream *this, const signed char * DEFINE_THISCALL_WRAPPER(ostream_write_unsigned_char, 12) ostream* __thiscall ostream_write_unsigned_char(ostream *this, const unsigned char *str, int count) { - FIXME("(%p %s %d) stub\n", this, str, count); - return this; + return ostream_write_char(this, (const char*) str, count); } /* ?writepad@ostream@@AAEAAV1@PBD0@Z */ diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index f846c9e8bd7..05630460d45 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -265,6 +265,7 @@ static ostream* (*__thiscall p_ostream_flush)(ostream*); static int (*__thiscall p_ostream_opfx)(ostream*); static void (*__thiscall p_ostream_osfx)(ostream*); static ostream* (*__thiscall p_ostream_put_char)(ostream*, char); +static ostream* (*__thiscall p_ostream_write_char)(ostream*, const char*, int); /* Emulate a __thiscall */ #ifdef __i386__ @@ -434,6 +435,7 @@ static BOOL init(void) SET(p_ostream_opfx, "?opfx@ostream@@QEAAHXZ"); SET(p_ostream_osfx, "?osfx@ostream@@QEAAXXZ"); SET(p_ostream_put_char, "?put@ostream@@QEAAAEAV1@D@Z"); + SET(p_ostream_write_char, "?write@ostream@@QEAAAEAV1@PEBDH@Z"); } else { p_operator_new = (void*)GetProcAddress(msvcrt, "??2@YAPAXI@Z"); p_operator_delete = (void*)GetProcAddress(msvcrt, "??3@YAXPAX@Z"); @@ -533,6 +535,7 @@ static BOOL init(void) SET(p_ostream_opfx, "?opfx@ostream@@QAEHXZ"); SET(p_ostream_osfx, "?osfx@ostream@@QAEXXZ"); SET(p_ostream_put_char, "?put@ostream@@QAEAAV1@D@Z"); + SET(p_ostream_write_char, "?write@ostream@@QAEAAV1@PBDH@Z"); } SET(p_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A"); SET(p_ios_lockc, "?lockc@ios@@KAXXZ"); @@ -2781,6 +2784,38 @@ if (0) /* crashes on native */ ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr); fb1.fd = fd; + /* write */ + pos = (ostream*) call_func3(p_ostream_write_char, &os1, "Your", 4); + ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos); + ok(os1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n", + IOSTATE_badbit|IOSTATE_failbit, os1.base_ios.state); + ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase); + ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr); + os1.base_ios.state = IOSTATE_goodbit; + os1.base_ios.width = 1; + pos = (ostream*) call_func3(p_ostream_write_char, &os1, "heart's", 7); + ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos); + ok(os1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, os1.base_ios.state); + ok(os1.base_ios.width == 0, "expected 0 got %d\n", os1.base_ios.width); + ok(fb1.base.pbase == fb1.base.base, "wrong put base, expected %p got %p\n", fb1.base.base, fb1.base.pbase); + ok(fb1.base.pptr == fb1.base.base + 7, "wrong put pointer, expected %p got %p\n", fb1.base.base + 7, fb1.base.pptr); + os1.base_ios.sb = NULL; +if (0) /* crashes on native */ + pos = (ostream*) call_func3(p_ostream_write_char, &os1, "been", 4); + os1.base_ios.sb = (streambuf*) &fb1; + os1.base_ios.width = 5; + call_func1(p_filebuf_sync, &fb1); + fd = fb1.fd; + fb1.fd = -1; + pos = (ostream*) call_func3(p_ostream_write_char, &os1, "aching,", 7); + ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos); + ok(os1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n", + IOSTATE_badbit|IOSTATE_failbit, os1.base_ios.state); + ok(os1.base_ios.width == 0, "expected 0 got %d\n", os1.base_ios.width); + ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase); + ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr); + fb1.fd = fd; + call_func1(p_ostream_vbase_dtor, &os1); call_func1(p_ostream_vbase_dtor, &os2); call_func1(p_filebuf_dtor, &fb1);