[08/10] msvcirt: Implement ostream::seekp
Iván Matellanes
matellanesivan at gmail.com
Mon Jun 6 06:52:56 CDT 2016
Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
---
dlls/msvcirt/msvcirt.c | 14 ++++++++++++--
dlls/msvcirt/tests/msvcirt.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 05738b1..81320bb 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -2465,7 +2465,12 @@ ostream* __thiscall ostream_put_unsigned_char(ostream *this, unsigned char c)
DEFINE_THISCALL_WRAPPER(ostream_seekp, 8)
ostream* __thiscall ostream_seekp(ostream *this, streampos pos)
{
- FIXME("(%p %d) stub\n", this, pos);
+ ios *base = ostream_get_ios(this);
+
+ TRACE("(%p %d)\n", this, pos);
+
+ if (streambuf_seekpos(base->sb, pos, OPENMODE_out) == EOF)
+ ios_clear(base, base->state | IOSTATE_failbit);
return this;
}
@@ -2474,7 +2479,12 @@ ostream* __thiscall ostream_seekp(ostream *this, streampos pos)
DEFINE_THISCALL_WRAPPER(ostream_seekp_offset, 12)
ostream* __thiscall ostream_seekp_offset(ostream *this, streamoff off, ios_seek_dir dir)
{
- FIXME("(%p %d %d) stub\n", this, off, dir);
+ ios *base = ostream_get_ios(this);
+
+ TRACE("(%p %d %d)\n", this, off, dir);
+
+ if (call_streambuf_seekoff(base->sb, off, dir, OPENMODE_out) == EOF)
+ ios_clear(base, base->state | IOSTATE_failbit);
return this;
}
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index e8a4ceb..d3d0e97 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -266,6 +266,8 @@ 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);
+static ostream* (*__thiscall p_ostream_seekp_offset)(ostream*, streamoff, ios_seek_dir);
+static ostream* (*__thiscall p_ostream_seekp)(ostream*, streampos);
/* Emulate a __thiscall */
#ifdef __i386__
@@ -436,6 +438,8 @@ static BOOL init(void)
SET(p_ostream_osfx, "?osfx at ostream@@QEAAXXZ");
SET(p_ostream_put_char, "?put at ostream@@QEAAAEAV1 at D@Z");
SET(p_ostream_write_char, "?write at ostream@@QEAAAEAV1 at PEBDH@Z");
+ SET(p_ostream_seekp_offset, "?seekp at ostream@@QEAAAEAV1 at JW4seek_dir@ios@@@Z");
+ SET(p_ostream_seekp, "?seekp at ostream@@QEAAAEAV1 at J@Z");
} else {
p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -536,6 +540,8 @@ static BOOL init(void)
SET(p_ostream_osfx, "?osfx at ostream@@QAEXXZ");
SET(p_ostream_put_char, "?put at ostream@@QAEAAV1 at D@Z");
SET(p_ostream_write_char, "?write at ostream@@QAEAAV1 at PBDH@Z");
+ SET(p_ostream_seekp_offset, "?seekp at ostream@@QAEAAV1 at JW4seek_dir@ios@@@Z");
+ SET(p_ostream_seekp, "?seekp at ostream@@QAEAAV1 at J@Z");
}
SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
@@ -2786,6 +2792,40 @@ 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;
+ /* seekp */
+ os1.base_ios.state = IOSTATE_eofbit;
+ pos = (ostream*) call_func3(p_ostream_seekp_offset, &os1, 0, SEEKDIR_beg);
+ ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos);
+ ok(os1.base_ios.state == IOSTATE_eofbit, "expected %d got %d\n", IOSTATE_eofbit, os1.base_ios.state);
+ ret = (int) call_func3(p_streambuf_xsputn, &fb1.base, "but", 3);
+ ok(ret == 3, "expected 3 got %d\n", ret);
+ 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 + 3, "wrong put pointer, expected %p got %p\n", fb1.base.base + 3, fb1.base.pptr);
+ pos = (ostream*) call_func3(p_ostream_seekp_offset, &os1, 0, SEEKDIR_end);
+ ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos);
+ ok(os1.base_ios.state == IOSTATE_eofbit, "expected %d got %d\n", IOSTATE_eofbit, 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);
+ pos = (ostream*) call_func3(p_ostream_seekp_offset, &os1, -1, SEEKDIR_beg);
+ ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos);
+ ok(os1.base_ios.state == (IOSTATE_eofbit|IOSTATE_failbit), "expected %d got %d\n",
+ IOSTATE_eofbit|IOSTATE_failbit, os1.base_ios.state);
+ ret = (int) call_func3(p_streambuf_xsputn, &fb1.base, "You're too shy", 14);
+ ok(ret == 14, "expected 14 got %d\n", ret);
+ 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 + 14, "wrong put pointer, expected %p got %p\n", fb1.base.base + 14, fb1.base.pptr);
+ pos = (ostream*) call_func2(p_ostream_seekp, &os1, 0);
+ ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos);
+ ok(os1.base_ios.state == (IOSTATE_eofbit|IOSTATE_failbit), "expected %d got %d\n",
+ IOSTATE_eofbit|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_badbit;
+ pos = (ostream*) call_func2(p_ostream_seekp, &os1, -1);
+ 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);
+
call_func1(p_ostream_vbase_dtor, &os1);
call_func1(p_ostream_vbase_dtor, &os2);
call_func1(p_filebuf_dtor, &fb1);
--
2.7.4
More information about the wine-patches
mailing list