Module: wine Branch: master Commit: c484ee409fb2c0f58ebfa64cfa520d8ef7639550 URL: http://source.winehq.org/git/wine.git/?a=commit;h=c484ee409fb2c0f58ebfa64cfa... Author: Iván Matellanes <matellanesivan(a)gmail.com> Date: Wed Jul 20 10:56:07 2016 +0100 msvcirt: Implement istream::tellg. Signed-off-by: Iván Matellanes <matellanes.ivan(a)gmail.com> Signed-off-by: Piotr Caban <piotr(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- 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 12a4809..617928a 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(a)istream@@AAEHPAD(a)Z */ diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index af8a235..fab46f5 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(a)istream@@QEAAAEAV1(a)J@Z"); SET(p_istream_seekg_offset, "?seekg(a)istream@@QEAAAEAV1(a)JW4seek_dir@ios@@@Z"); SET(p_istream_sync, "?sync(a)istream@@QEAAHXZ"); + SET(p_istream_tellg, "?tellg(a)istream@@QEAAJXZ"); } else { p_operator_new = (void*)GetProcAddress(msvcrt, "??2(a)YAPAXI@Z"); p_operator_delete = (void*)GetProcAddress(msvcrt, "??3(a)YAXPAX@Z"); @@ -670,6 +672,7 @@ static BOOL init(void) SET(p_istream_seekg, "?seekg(a)istream@@QAEAAV1(a)J@Z"); SET(p_istream_seekg_offset, "?seekg(a)istream@@QAEAAV1(a)JW4seek_dir@ios@@@Z"); SET(p_istream_sync, "?sync(a)istream@@QAEHXZ"); + SET(p_istream_tellg, "?tellg(a)istream@@QAEJXZ"); } SET(p_ios_static_lock, "?x_lockc(a)ios@@0U_CRT_CRITICAL_SECTION@@A"); SET(p_ios_lockc, "?lockc(a)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);