Commit 5101a90b authored by Iván Matellanes's avatar Iván Matellanes Committed by Alexandre Julliard

msvcirt: Reset the pointers on file sync in most cases.

parent e6c85e84
......@@ -1126,8 +1126,8 @@ int __thiscall filebuf_sync(filebuf *this)
count = this->base.pptr - this->base.pbase;
if (count > 0 && _write(this->fd, this->base.pbase, count) != count)
return EOF;
this->base.pbase = this->base.pptr = this->base.epptr = NULL;
}
this->base.pbase = this->base.pptr = this->base.epptr = NULL;
/* flush input buffer */
if (this->base.egptr != NULL) {
offset = this->base.egptr - this->base.gptr;
......@@ -1143,8 +1143,8 @@ int __thiscall filebuf_sync(filebuf *this)
if (_lseek(this->fd, -offset, SEEK_CUR) < 0)
return EOF;
}
this->base.eback = this->base.gptr = this->base.egptr = NULL;
}
this->base.eback = this->base.gptr = this->base.egptr = NULL;
return 0;
}
......
......@@ -1419,6 +1419,46 @@ static void test_filebuf(void)
ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr);
ok(_tell(fb1.fd) == 0, "_tell failed\n");
fb1.base.pbase = fb1.base.pptr = fb1.base.base;
ret = (int) call_func1(p_filebuf_sync, &fb1);
ok(ret == 0, "wrong return, expected 0 got %d\n", ret);
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);
fb1.base.epptr = fb1.base.ebuf;
ret = (int) call_func1(p_filebuf_sync, &fb1);
ok(ret == 0, "wrong return, expected 0 got %d\n", ret);
ok(fb1.base.epptr == NULL, "wrong put end, expected %p got %p\n", NULL, fb1.base.epptr);
fb1.base.pbase = fb1.base.base;
ret = (int) call_func1(p_filebuf_sync, &fb1);
ok(ret == 0, "wrong return, expected 0 got %d\n", ret);
ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase);
fb1.base.pbase = fb1.base.base;
fb1.base.epptr = fb1.base.ebuf;
ret = (int) call_func1(p_filebuf_sync, &fb1);
ok(ret == 0, "wrong return, expected 0 got %d\n", ret);
ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase);
ok(fb1.base.epptr == NULL, "wrong put end, expected %p got %p\n", NULL, fb1.base.epptr);
fb1.base.eback = fb1.base.base;
ret = (int) call_func1(p_filebuf_sync, &fb1);
ok(ret == 0, "wrong return, expected 0 got %d\n", ret);
ok(fb1.base.eback == NULL, "wrong get base, expected %p got %p\n", NULL, fb1.base.eback);
fb1.base.eback = fb1.base.gptr = fb1.base.base;
ret = (int) call_func1(p_filebuf_sync, &fb1);
ok(ret == 0, "wrong return, expected 0 got %d\n", ret);
ok(fb1.base.gptr == NULL, "wrong get base, expected %p got %p\n", NULL, fb1.base.gptr);
fb1.base.gptr = fb1.base.base;
fb1.base.egptr = fb1.base.base + 100;
fb1.base.pbase = fb1.base.base;
ret = (int) call_func1(p_filebuf_sync, &fb1);
ok(ret == -1, "wrong return, expected -1 got %d\n", ret);
ok(fb1.base.gptr == fb1.base.base, "wrong get base, expected %p got %p\n", fb1.base.base, fb1.base.gptr);
ok(fb1.base.egptr == fb1.base.base + 100, "wrong get base, expected %p got %p\n", fb1.base.base + 100, fb1.base.egptr);
ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase);
fb1.base.egptr = NULL;
ret = (int) call_func1(p_filebuf_sync, &fb1);
ok(ret == 0, "wrong return, expected 0 got %d\n", ret);
ok(fb1.base.gptr == NULL, "wrong get base, expected %p got %p\n", NULL, fb1.base.gptr);
ok(fb1.base.egptr == NULL, "wrong get base, expected %p got %p\n", NULL, fb1.base.egptr);
ret = (int) call_func1(p_filebuf_sync, &fb2);
ok(ret == -1, "wrong return, expected -1 got %d\n", ret);
fb3.base.eback = fb3.base.base;
......
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