[09/10] msvcirt: Implement ostream::tellp

Iván Matellanes matellanesivan at gmail.com
Mon Jun 6 06:52:57 CDT 2016


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

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 81320bb..696041a 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -2493,8 +2493,14 @@ ostream* __thiscall ostream_seekp_offset(ostream *this, streamoff off, ios_seek_
 DEFINE_THISCALL_WRAPPER(ostream_tellp, 4)
 streampos __thiscall ostream_tellp(ostream *this)
 {
-    FIXME("(%p) stub\n", this);
-    return 0;
+    ios *base = ostream_get_ios(this);
+    streampos pos;
+
+    TRACE("(%p)\n", this);
+
+    if ((pos = call_streambuf_seekoff(base->sb, 0, SEEKDIR_cur, OPENMODE_out)) == EOF)
+        ios_clear(base, base->state | IOSTATE_failbit);
+    return pos;
 }
 
 /* ?write at ostream@@QAEAAV1 at PBDH@Z */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index d3d0e97..d180c6d 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -268,6 +268,7 @@ 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);
+static streampos (*__thiscall p_ostream_tellp)(ostream*);
 
 /* Emulate a __thiscall */
 #ifdef __i386__
@@ -440,6 +441,7 @@ static BOOL init(void)
         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");
+        SET(p_ostream_tellp, "?tellp at ostream@@QEAAJXZ");
     } else {
         p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
         p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -542,6 +544,7 @@ static BOOL init(void)
         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_ostream_tellp, "?tellp at ostream@@QAEJXZ");
     }
     SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
     SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
@@ -2826,6 +2829,30 @@ if (0) /* crashes on native */
     ok(os1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
         IOSTATE_badbit|IOSTATE_failbit, os1.base_ios.state);
 
+    /* tellp */
+    ret = (int) call_func1(p_ostream_tellp, &os1);
+    ok(ret == 0, "wrong return, expected 0 got %d\n", ret);
+    ok(os1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
+        IOSTATE_badbit|IOSTATE_failbit, os1.base_ios.state);
+    ret = (int) call_func3(p_streambuf_xsputn, &fb1.base, "to say it", 9);
+    ok(ret == 9, "expected 9 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 + 9, "wrong put pointer, expected %p got %p\n", fb1.base.base + 9, fb1.base.pptr);
+    ret = (int) call_func1(p_ostream_tellp, &os1);
+    ok(ret == 9, "wrong return, expected 9 got %d\n", ret);
+    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_eofbit;
+    fd = fb1.fd;
+    fb1.fd = -1;
+    ret = (int) call_func1(p_ostream_tellp, &os1);
+    ok(ret == EOF, "wrong return, expected EOF got %d\n", ret);
+    ok(os1.base_ios.state == (IOSTATE_eofbit|IOSTATE_failbit), "expected %d got %d\n",
+        IOSTATE_eofbit|IOSTATE_failbit, os1.base_ios.state);
+    fb1.fd = fd;
+
     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