[2/3] msvcirt: Implement stdiobuf::seekoff (resend)

Iván Matellanes matellanesivan at gmail.com
Wed Oct 7 16:19:31 CDT 2015


Signed-off-by: Iván Matellanes <matellanesivan at gmail.com>
---
 dlls/msvcirt/msvcirt.c       |  7 ++++--
 dlls/msvcirt/tests/msvcirt.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 1eefe73..bfef1a3 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -1571,8 +1571,11 @@ int __thiscall stdiobuf_pbackfail(stdiobuf *this, int c)
 DEFINE_THISCALL_WRAPPER(stdiobuf_seekoff, 16)
 streampos __thiscall stdiobuf_seekoff(stdiobuf *this, streamoff offset, ios_seek_dir dir, int mode)
 {
-    FIXME("(%p %d %d %d) stub\n", this, offset, dir, mode);
-    return EOF;
+    TRACE("(%p %d %d %d)\n", this, offset, dir, mode);
+    call_streambuf_overflow(&this->base, EOF);
+    if (fseek(this->file, offset, dir))
+        return EOF;
+    return ftell(this->file);
 }
 
 /* ?setrwbuf at stdiobuf@@QAEHHH at Z */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 758062c..704a6c2 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -210,6 +210,7 @@ static int (*__thiscall p_strstreambuf_underflow)(strstreambuf*);
 static stdiobuf* (*__thiscall p_stdiobuf_file_ctor)(stdiobuf*, FILE*);
 static void (*__thiscall p_stdiobuf_dtor)(stdiobuf*);
 static int (*__thiscall p_stdiobuf_overflow)(stdiobuf*, int);
+static streampos (*__thiscall p_stdiobuf_seekoff)(stdiobuf*, streamoff, ios_seek_dir, int);
 static int (*__thiscall p_stdiobuf_setrwbuf)(stdiobuf*, int, int);
 static int (*__thiscall p_stdiobuf_sync)(stdiobuf*);
 static int (*__thiscall p_stdiobuf_underflow)(stdiobuf*);
@@ -375,6 +376,7 @@ static BOOL init(void)
         SET(p_stdiobuf_file_ctor, "??0stdiobuf@@QEAA at PEAU_iobuf@@@Z");
         SET(p_stdiobuf_dtor, "??1stdiobuf@@UEAA at XZ");
         SET(p_stdiobuf_overflow, "?overflow at stdiobuf@@UEAAHH at Z");
+        SET(p_stdiobuf_seekoff, "?seekoff at stdiobuf@@UEAAJJW4seek_dir at ios@@H at Z");
         SET(p_stdiobuf_setrwbuf, "?setrwbuf at stdiobuf@@QEAAHHH at Z");
         SET(p_stdiobuf_sync, "?sync at stdiobuf@@UEAAHXZ");
         SET(p_stdiobuf_underflow, "?underflow at stdiobuf@@UEAAHXZ");
@@ -460,6 +462,7 @@ static BOOL init(void)
         SET(p_stdiobuf_file_ctor, "??0stdiobuf@@QAE at PAU_iobuf@@@Z");
         SET(p_stdiobuf_dtor, "??1stdiobuf@@UAE at XZ");
         SET(p_stdiobuf_overflow, "?overflow at stdiobuf@@UAEHH at Z");
+        SET(p_stdiobuf_seekoff, "?seekoff at stdiobuf@@UAEJJW4seek_dir at ios@@H at Z");
         SET(p_stdiobuf_setrwbuf, "?setrwbuf at stdiobuf@@QAEHHH at Z");
         SET(p_stdiobuf_sync, "?sync at stdiobuf@@UAEHXZ");
         SET(p_stdiobuf_underflow, "?underflow at stdiobuf@@UAEHXZ");
@@ -2048,6 +2051,63 @@ static void test_stdiobuf(void)
     ok(ret == 0, "expected 0 got %d\n", ret);
     ok(stb1.base.unbuffered == 1, "wrong unbuffered value, expected 1 got %d\n", stb1.base.unbuffered);
 
+    /* seekoff */
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 0, SEEKDIR_beg, OPENMODE_in);
+    ok(ret == 0, "expected 0 got %d\n", ret);
+    stb1.base.unbuffered = 0;
+    ret = (int) call_func3(p_streambuf_xsputn, &stb1.base, "Never gonna say goodbye", 22);
+    ok(ret == 22, "expected 22 got %d\n", ret);
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 5, SEEKDIR_beg, OPENMODE_in);
+    ok(ret == 5, "expected 5 got %d\n", ret);
+    ok(stb1.base.pptr == stb1.base.pbase + 22, "wrong put pointer, expected %p got %p\n", stb1.base.pbase + 22, stb1.base.pptr);
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 300, SEEKDIR_beg, OPENMODE_in);
+    ok(ret == 300, "expected 300 got %d\n", ret);
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, -310, SEEKDIR_cur, OPENMODE_in);
+    ok(ret == EOF, "expected EOF got %d\n", ret);
+    stb1.base.eback = stb1.base.base;
+    stb1.base.gptr = stb1.base.egptr = stb1.base.pbase = stb1.base.base + 10;
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, -280, SEEKDIR_cur, OPENMODE_in);
+    ok(ret == 20, "expected 20 got %d\n", ret);
+    stb1.base.gptr = stb1.base.eback;
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 80, SEEKDIR_cur, OPENMODE_in);
+    ok(ret == 100, "expected 100 got %d\n", ret);
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 0, SEEKDIR_end, OPENMODE_in);
+    ok(ret == 49, "expected 49 got %d\n", ret);
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 1, SEEKDIR_end, OPENMODE_in);
+    ok(ret == 50, "expected 50 got %d\n", ret);
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, -60, SEEKDIR_end, OPENMODE_in);
+    ok(ret == EOF, "expected EOF got %d\n", ret);
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, -20, SEEKDIR_end, OPENMODE_out);
+    ok(ret == 29, "expected 29 got %d\n", ret);
+    stb1.base.eback = stb1.base.gptr = stb1.base.egptr = NULL;
+    stb1.base.pptr = stb1.base.pbase;
+    stb1.base.unbuffered = 1;
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, 0, SEEKDIR_beg, OPENMODE_in);
+    ok(ret == 0, "expected 0 got %d\n", ret);
+    stb2.base.pptr += 10;
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, 20, SEEKDIR_beg, OPENMODE_in);
+    ok(ret == 20, "expected 20 got %d\n", ret);
+    ok(stb2.base.pptr == stb2.base.pbase + 10, "wrong put pointer, expected %p got %p\n", stb2.base.pbase + 10, stb2.base.pptr);
+    stb2.base.unbuffered = 0;
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, 10, SEEKDIR_cur, OPENMODE_in);
+    ok(ret == 40, "expected 40 got %d\n", ret);
+    ok(stb2.base.pptr == stb2.base.pbase, "wrong put pointer, expected %p got %p\n", stb2.base.pbase, stb2.base.pptr);
+    stb2.base.gptr = stb2.base.eback;
+    stb2.base.pptr += 5;
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, -50, SEEKDIR_cur, OPENMODE_in|OPENMODE_out);
+    ok(ret == EOF, "expected EOF got %d\n", ret);
+    ok(stb2.base.pptr == stb2.base.pbase, "wrong put pointer, expected %p got %p\n", stb2.base.pbase, stb2.base.pptr);
+    stb2.base.pbase = stb2.base.pptr = stb2.base.epptr = NULL;
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, 0, SEEKDIR_end, OPENMODE_in|OPENMODE_out);
+    ok(ret == 48, "expected 48 got %d\n", ret);
+    ok(stb2.base.pbase == stb2.base.base + 32, "wrong put pointer, expected %p got %p\n", stb2.base.base + 32, stb2.base.pbase);
+    ok(stb2.base.pptr == stb2.base.base + 32, "wrong put pointer, expected %p got %p\n", stb2.base.base + 32, stb2.base.pptr);
+    ok(stb2.base.epptr == stb2.base.ebuf, "wrong put pointer, expected %p got %p\n", stb2.base.ebuf, stb2.base.epptr);
+    ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, -28, SEEKDIR_end, -1);
+    ok(ret == 20, "expected 20 got %d\n", ret);
+    stb2.base.gptr = stb2.base.egptr;
+    stb2.base.unbuffered = 1;
+
     call_func1(p_stdiobuf_dtor, &stb1);
     call_func1(p_stdiobuf_dtor, &stb2);
     fclose(file1);
-- 
2.1.4




More information about the wine-patches mailing list