Commit 1235aa5d authored by Iván Matellanes's avatar Iván Matellanes Committed by Alexandre Julliard

msvcirt: Implement istream::sync.

parent 3c9fd382
......@@ -3378,8 +3378,16 @@ istream* __thiscall istream_seekg_offset(istream *this, streamoff off, ios_seek_
DEFINE_THISCALL_WRAPPER(istream_sync, 4)
int __thiscall istream_sync(istream *this)
{
FIXME("(%p) stub\n", this);
return 0;
ios *base = istream_get_ios(this);
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 */
......
......@@ -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_seekg)(istream*, streampos);
static istream* (*__thiscall p_istream_seekg_offset)(istream*, streamoff, ios_seek_dir);
static int (*__thiscall p_istream_sync)(istream*);
/* Emulate a __thiscall */
#ifdef __i386__
......@@ -534,6 +535,7 @@ static BOOL init(void)
SET(p_istream_read, "?read@istream@@QEAAAEAV1@PEADH@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_sync, "?sync@istream@@QEAAHXZ");
} else {
p_operator_new = (void*)GetProcAddress(msvcrt, "??2@YAPAXI@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_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_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A");
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(_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, &is2);
call_func1(p_ostream_vbase_dtor, &os);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment