[1/5] msvcirt: Implement istream::seekg

Iván Matellanes matellanesivan at gmail.com
Wed Jul 20 04:56:05 CDT 2016


Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
---
 dlls/msvcirt/msvcirt.c       | 18 +++++++++++++--
 dlls/msvcirt/tests/msvcirt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index f016328..1715f80 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -3346,7 +3346,14 @@ istream* __thiscall istream_read_unsigned(istream *this, unsigned char *str, int
 DEFINE_THISCALL_WRAPPER(istream_seekg, 8)
 istream* __thiscall istream_seekg(istream *this, streampos pos)
 {
-    FIXME("(%p %d) stub\n", this, pos);
+    ios *base = istream_get_ios(this);
+
+    TRACE("(%p %d)\n", this, pos);
+
+    ios_lockbuf(base);
+    if (streambuf_seekpos(base->sb, pos, OPENMODE_in) == EOF)
+        ios_clear(base, base->state | IOSTATE_failbit);
+    ios_unlockbuf(base);
     return this;
 }
 
@@ -3355,7 +3362,14 @@ istream* __thiscall istream_seekg(istream *this, streampos pos)
 DEFINE_THISCALL_WRAPPER(istream_seekg_offset, 12)
 istream* __thiscall istream_seekg_offset(istream *this, streamoff off, ios_seek_dir dir)
 {
-    FIXME("(%p %d %d) stub\n", this, off, dir);
+    ios *base = istream_get_ios(this);
+
+    TRACE("(%p %d %d)\n", this, off, dir);
+
+    ios_lockbuf(base);
+    if (call_streambuf_seekoff(base->sb, off, dir, OPENMODE_in) == EOF)
+        ios_clear(base, base->state | IOSTATE_failbit);
+    ios_unlockbuf(base);
     return this;
 }
 
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 28f5dbf..0bb3e98 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -321,6 +321,8 @@ static istream* (*__thiscall p_istream_ignore)(istream*, int, int);
 static int (*__thiscall p_istream_peek)(istream*);
 static istream* (*__thiscall p_istream_putback)(istream*, char);
 static istream* (*__thiscall p_istream_read)(istream*, char*, int);
+static istream* (*__thiscall p_istream_seekg)(istream*, streampos);
+static istream* (*__thiscall p_istream_seekg_offset)(istream*, streamoff, ios_seek_dir);
 
 /* Emulate a __thiscall */
 #ifdef __i386__
@@ -530,6 +532,8 @@ static BOOL init(void)
         SET(p_istream_peek, "?peek at istream@@QEAAHXZ");
         SET(p_istream_putback, "?putback at istream@@QEAAAEAV1 at D@Z");
         SET(p_istream_read, "?read at istream@@QEAAAEAV1 at PEADH@Z");
+        SET(p_istream_seekg, "?seekg at istream@@QEAAAEAV1 at J@Z");
+        SET(p_istream_seekg_offset, "?seekg at istream@@QEAAAEAV1 at JW4seek_dir@ios@@@Z");
     } else {
         p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
         p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -661,6 +665,8 @@ static BOOL init(void)
         SET(p_istream_peek, "?peek at istream@@QAEHXZ");
         SET(p_istream_putback, "?putback at istream@@QAEAAV1 at D@Z");
         SET(p_istream_read, "?read at istream@@QAEAAV1 at PADH@Z");
+        SET(p_istream_seekg, "?seekg at istream@@QAEAAV1 at J@Z");
+        SET(p_istream_seekg_offset, "?seekg at istream@@QAEAAV1 at JW4seek_dir@ios@@@Z");
     }
     SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
     SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
@@ -4495,6 +4501,54 @@ if (0) /* crashes on native */
     ok(buffer[0] == 'A', "expected 'A' got %d\n", buffer[0]);
     fb1.base.gptr = fb1.base.egptr;
 
+    /* seekg */
+    is1.extract_delim = is1.count = 0xabababab;
+    pis = call_func2(p_istream_seekg, &is1, 0);
+    ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
+    ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+    ok(_tell(fb1.fd) == 0, "expected 0 got %d\n", _tell(fb1.fd));
+if (0) /* crashes on native */
+    is1.base_ios.sb = NULL;
+    pis = call_func2(p_istream_seekg, &is1, -5);
+    ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
+    ok(is1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, is1.base_ios.state);
+    ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+    ok(_tell(fb1.fd) == 0, "expected 0 got %d\n", _tell(fb1.fd));
+    fb1.base.epptr = fb1.base.ebuf;
+    pis = call_func2(p_istream_seekg, &is1, 5);
+    ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
+    ok(is1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, is1.base_ios.state);
+    ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+    ok(fb1.base.epptr == NULL, "wrong put end, expected %p got %p\n", NULL, fb1.base.epptr);
+    ok(_tell(fb1.fd) == 5, "expected 5 got %d\n", _tell(fb1.fd));
+    is1.base_ios.state = IOSTATE_goodbit;
+    fd = fb1.fd;
+    fb1.fd = -1;
+    pis = call_func2(p_istream_seekg, &is1, 0);
+    ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
+    ok(is1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, is1.base_ios.state);
+    ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+    fb1.base.eback = fb1.base.gptr = fb1.base.base;
+    fb1.base.egptr = fb1.base.base + 30;
+    pis = call_func3(p_istream_seekg_offset, &is1, 0, SEEKDIR_end);
+    ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
+    ok(is1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, is1.base_ios.state);
+    ok(fb1.base.gptr == fb1.base.base, "wrong get pointer, expected %p got %p\n", fb1.base.base, fb1.base.gptr);
+    is1.base_ios.state = IOSTATE_goodbit;
+    fb1.fd = fd;
+    pis = call_func3(p_istream_seekg_offset, &is1, 0, SEEKDIR_end);
+    ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
+    ok(is1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, is1.base_ios.state);
+    ok(fb1.base.gptr == fb1.base.base, "wrong get pointer, expected %p got %p\n", fb1.base.base, fb1.base.gptr);
+if (0) /* crashes on native */
+    is1.base_ios.sb = NULL;
+    fb1.base.gptr = fb1.base.egptr;
+    pis = call_func3(p_istream_seekg_offset, &is1, 0, SEEKDIR_end);
+    ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
+    ok(is1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, is1.base_ios.state);
+    ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+    ok(_tell(fb1.fd) == 24, "expected 24 got %d\n", _tell(fb1.fd));
+
     call_func1(p_istream_vbase_dtor, &is1);
     call_func1(p_istream_vbase_dtor, &is2);
     call_func1(p_ostream_vbase_dtor, &os);
-- 
2.7.4




More information about the wine-patches mailing list