From c484ee409fb2c0f58ebfa64cfa520d8ef7639550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Matellanes?= Date: Wed, 20 Jul 2016 10:56:07 +0100 Subject: [PATCH] msvcirt: Implement istream::tellg. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Iván Matellanes Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcirt/msvcirt.c | 12 ++++++++++-- dlls/msvcirt/tests/msvcirt.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 12a4809dcfd..617928a5b71 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -3395,8 +3395,16 @@ int __thiscall istream_sync(istream *this) DEFINE_THISCALL_WRAPPER(istream_tellg, 4) streampos __thiscall istream_tellg(istream *this) { - FIXME("(%p) stub\n", this); - return 0; + ios *base = istream_get_ios(this); + streampos pos; + + TRACE("(%p)\n", this); + + ios_lockbuf(base); + if ((pos = call_streambuf_seekoff(base->sb, 0, SEEKDIR_cur, OPENMODE_in)) == EOF) + ios_clear(base, base->state | IOSTATE_failbit); + ios_unlockbuf(base); + return pos; } /* ?getint@istream@@AAEHPAD@Z */ diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index af8a235c74d..fab46f5351d 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -324,6 +324,7 @@ 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); static int (*__thiscall p_istream_sync)(istream*); +static streampos (*__thiscall p_istream_tellg)(istream*); /* Emulate a __thiscall */ #ifdef __i386__ @@ -536,6 +537,7 @@ static BOOL init(void) SET(p_istream_seekg, "?seekg@istream@@QEAAAEAV1@J@Z"); SET(p_istream_seekg_offset, "?seekg@istream@@QEAAAEAV1@JW4seek_dir@ios@@@Z"); SET(p_istream_sync, "?sync@istream@@QEAAHXZ"); + SET(p_istream_tellg, "?tellg@istream@@QEAAJXZ"); } else { p_operator_new = (void*)GetProcAddress(msvcrt, "??2@YAPAXI@Z"); p_operator_delete = (void*)GetProcAddress(msvcrt, "??3@YAXPAX@Z"); @@ -670,6 +672,7 @@ static BOOL init(void) SET(p_istream_seekg, "?seekg@istream@@QAEAAV1@J@Z"); SET(p_istream_seekg_offset, "?seekg@istream@@QAEAAV1@JW4seek_dir@ios@@@Z"); SET(p_istream_sync, "?sync@istream@@QAEHXZ"); + SET(p_istream_tellg, "?tellg@istream@@QAEJXZ"); } SET(p_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A"); SET(p_ios_lockc, "?lockc@ios@@KAXXZ"); @@ -4588,6 +4591,29 @@ if (0) /* crashes on native */ IOSTATE_badbit|IOSTATE_failbit|IOSTATE_eofbit, is1.base_ios.state); fb1.fd = fd; + /* tellg */ + ret = (int) call_func1(p_istream_tellg, &is1); + ok(ret == 24, "expected 24 got %d\n", ret); + ok(is1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit|IOSTATE_eofbit), "expected %d got %d\n", + IOSTATE_badbit|IOSTATE_failbit|IOSTATE_eofbit, is1.base_ios.state); + is1.base_ios.state = IOSTATE_goodbit; + ret = (int) call_func1(p_istream_tellg, &is1); + ok(ret == 24, "expected 24 got %d\n", ret); + ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, is1.base_ios.state); +if (0) /* crashes on native */ + is1.base_ios.sb = NULL; + fb1.base.eback = fb1.base.gptr = fb1.base.base; + fb1.base.egptr = fb1.base.base + 30; + ret = (int) call_func1(p_istream_tellg, &is1); + ok(ret == EOF, "expected -1 got %d\n", ret); + ok(is1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, is1.base_ios.state); + is1.base_ios.state = IOSTATE_eofbit; + ret = (int) call_func1(p_istream_tellg, &is1); + ok(ret == EOF, "expected -1 got %d\n", ret); + ok(is1.base_ios.state == (IOSTATE_eofbit|IOSTATE_failbit), "expected %d got %d\n", + IOSTATE_eofbit|IOSTATE_failbit, is1.base_ios.state); + fb1.base.eback = fb1.base.gptr = fb1.base.egptr = NULL; + call_func1(p_istream_vbase_dtor, &is1); call_func1(p_istream_vbase_dtor, &is2); call_func1(p_ostream_vbase_dtor, &os);