Module: wine Branch: master Commit: 3f32455f01aaefb50ccb323ddbdd5974f533f253 URL: http://source.winehq.org/git/wine.git/?a=commit;h=3f32455f01aaefb50ccb323ddb...
Author: Iván Matellanes matellanesivan@gmail.com Date: Tue Jun 14 15:40:23 2016 +0100
msvcirt: Implement ostream::tellp.
Signed-off-by: Iván Matellanes matellanes.ivan@gmail.com Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
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@ostream@@QAEAAV1@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@ostream@@QEAAAEAV1@PEBDH@Z"); SET(p_ostream_seekp_offset, "?seekp@ostream@@QEAAAEAV1@JW4seek_dir@ios@@@Z"); SET(p_ostream_seekp, "?seekp@ostream@@QEAAAEAV1@J@Z"); + SET(p_ostream_tellp, "?tellp@ostream@@QEAAJXZ"); } else { p_operator_new = (void*)GetProcAddress(msvcrt, "??2@YAPAXI@Z"); p_operator_delete = (void*)GetProcAddress(msvcrt, "??3@YAXPAX@Z"); @@ -542,6 +544,7 @@ static BOOL init(void) SET(p_ostream_write_char, "?write@ostream@@QAEAAV1@PBDH@Z"); SET(p_ostream_seekp_offset, "?seekp@ostream@@QAEAAV1@JW4seek_dir@ios@@@Z"); SET(p_ostream_seekp, "?seekp@ostream@@QAEAAV1@J@Z"); + SET(p_ostream_tellp, "?tellp@ostream@@QAEJXZ"); } SET(p_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A"); SET(p_ios_lockc, "?lockc@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);