[v2 09/10] msvcirt: Implement ostream::tellp
Iván Matellanes
matellanesivan at gmail.com
Tue Jun 14 09:40:23 CDT 2016
v2: Added thread locking
Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
---
dlls/msvcirt/msvcirt.c | 12 ++++++++++--
dlls/msvcirt/tests/msvcirt.c | 27 +++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 2464d4f..0879a1d 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -2511,8 +2511,16 @@ 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);
+
+ ios_lockbuf(base);
+ if ((pos = call_streambuf_seekoff(base->sb, 0, SEEKDIR_cur, OPENMODE_out)) == EOF)
+ ios_clear(base, base->state | IOSTATE_failbit);
+ ios_unlockbuf(base);
+ return pos;
}
/* ?write at ostream@@QAEAAV1 at PBDH@Z */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 3a6cb6e..baabd65 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");
@@ -2856,6 +2859,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