msvcirt: Implement istream::sync.

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>
This commit is contained in:
Iván Matellanes 2016-07-20 10:56:06 +01:00 committed by Alexandre Julliard
parent 3c9fd38283
commit 1235aa5d1b
2 changed files with 49 additions and 2 deletions

View File

@ -3378,8 +3378,16 @@ istream* __thiscall istream_seekg_offset(istream *this, streamoff off, ios_seek_
DEFINE_THISCALL_WRAPPER(istream_sync, 4) DEFINE_THISCALL_WRAPPER(istream_sync, 4)
int __thiscall istream_sync(istream *this) int __thiscall istream_sync(istream *this)
{ {
FIXME("(%p) stub\n", this); ios *base = istream_get_ios(this);
return 0; int ret;
TRACE("(%p)\n", this);
ios_lockbuf(base);
if ((ret = call_streambuf_sync(base->sb)) == EOF)
ios_clear(base, base->state | IOSTATE_badbit | IOSTATE_failbit);
ios_unlockbuf(base);
return ret;
} }
/* ?tellg@istream@@QAEJXZ */ /* ?tellg@istream@@QAEJXZ */

View File

@ -323,6 +323,7 @@ static istream* (*__thiscall p_istream_putback)(istream*, char);
static istream* (*__thiscall p_istream_read)(istream*, char*, int); static istream* (*__thiscall p_istream_read)(istream*, char*, int);
static istream* (*__thiscall p_istream_seekg)(istream*, streampos); static istream* (*__thiscall p_istream_seekg)(istream*, streampos);
static istream* (*__thiscall p_istream_seekg_offset)(istream*, streamoff, ios_seek_dir); static istream* (*__thiscall p_istream_seekg_offset)(istream*, streamoff, ios_seek_dir);
static int (*__thiscall p_istream_sync)(istream*);
/* Emulate a __thiscall */ /* Emulate a __thiscall */
#ifdef __i386__ #ifdef __i386__
@ -534,6 +535,7 @@ static BOOL init(void)
SET(p_istream_read, "?read@istream@@QEAAAEAV1@PEADH@Z"); SET(p_istream_read, "?read@istream@@QEAAAEAV1@PEADH@Z");
SET(p_istream_seekg, "?seekg@istream@@QEAAAEAV1@J@Z"); SET(p_istream_seekg, "?seekg@istream@@QEAAAEAV1@J@Z");
SET(p_istream_seekg_offset, "?seekg@istream@@QEAAAEAV1@JW4seek_dir@ios@@@Z"); SET(p_istream_seekg_offset, "?seekg@istream@@QEAAAEAV1@JW4seek_dir@ios@@@Z");
SET(p_istream_sync, "?sync@istream@@QEAAHXZ");
} else { } else {
p_operator_new = (void*)GetProcAddress(msvcrt, "??2@YAPAXI@Z"); p_operator_new = (void*)GetProcAddress(msvcrt, "??2@YAPAXI@Z");
p_operator_delete = (void*)GetProcAddress(msvcrt, "??3@YAXPAX@Z"); p_operator_delete = (void*)GetProcAddress(msvcrt, "??3@YAXPAX@Z");
@ -667,6 +669,7 @@ static BOOL init(void)
SET(p_istream_read, "?read@istream@@QAEAAV1@PADH@Z"); SET(p_istream_read, "?read@istream@@QAEAAV1@PADH@Z");
SET(p_istream_seekg, "?seekg@istream@@QAEAAV1@J@Z"); SET(p_istream_seekg, "?seekg@istream@@QAEAAV1@J@Z");
SET(p_istream_seekg_offset, "?seekg@istream@@QAEAAV1@JW4seek_dir@ios@@@Z"); SET(p_istream_seekg_offset, "?seekg@istream@@QAEAAV1@JW4seek_dir@ios@@@Z");
SET(p_istream_sync, "?sync@istream@@QAEHXZ");
} }
SET(p_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A"); SET(p_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A");
SET(p_ios_lockc, "?lockc@ios@@KAXXZ"); SET(p_ios_lockc, "?lockc@ios@@KAXXZ");
@ -4549,6 +4552,42 @@ if (0) /* crashes on native */
ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr); ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
ok(_tell(fb1.fd) == 24, "expected 24 got %d\n", _tell(fb1.fd)); ok(_tell(fb1.fd) == 24, "expected 24 got %d\n", _tell(fb1.fd));
/* sync */
ret = (int) call_func1(p_istream_sync, &is1);
ok(ret == 0, "expected 0 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_badbit;
ret = (int) call_func1(p_istream_sync, &is1);
ok(ret == 0, "expected 0 got %d\n", ret);
ok(is1.base_ios.state == IOSTATE_badbit, "expected %d got %d\n", IOSTATE_badbit, is1.base_ios.state);
is1.base_ios.state = IOSTATE_goodbit;
ret = (int) call_func1(p_istream_sync, &is1);
ok(ret == 0, "expected 0 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_sync, &is1);
ok(ret == EOF, "expected -1 got %d\n", ret);
ok(is1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
IOSTATE_badbit|IOSTATE_failbit, is1.base_ios.state);
ok(fb1.base.gptr == fb1.base.base, "wrong get pointer, expected %p got %p\n", fb1.base.base, fb1.base.gptr);
fb1.base.gptr = fb1.base.egptr;
ret = (int) call_func1(p_istream_sync, &is1);
ok(ret == 0, "expected 0 got %d\n", ret);
ok(is1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
IOSTATE_badbit|IOSTATE_failbit, is1.base_ios.state);
ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
is1.base_ios.state = IOSTATE_eofbit;
fd = fb1.fd;
fb1.fd = -1;
ret = (int) call_func1(p_istream_sync, &is1);
ok(ret == EOF, "expected -1 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);
fb1.fd = fd;
call_func1(p_istream_vbase_dtor, &is1); call_func1(p_istream_vbase_dtor, &is1);
call_func1(p_istream_vbase_dtor, &is2); call_func1(p_istream_vbase_dtor, &is2);
call_func1(p_ostream_vbase_dtor, &os); call_func1(p_ostream_vbase_dtor, &os);