Module: wine Branch: master Commit: 28c61981ad7acc005177ae91ebcdac3c112fbfd6 URL: http://source.winehq.org/git/wine.git/?a=commit;h=28c61981ad7acc005177ae91eb...
Author: Iván Matellanes matellanesivan@gmail.com Date: Mon Aug 10 20:09:07 2015 +0200
msvcirt: Implement filebuf::setbuf.
---
dlls/msvcirt/msvcirt.c | 12 ++++++++++-- dlls/msvcirt/tests/msvcirt.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 83184a0..17525cf 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -1001,8 +1001,16 @@ streampos __thiscall filebuf_seekoff(filebuf *this, streamoff offset, ios_seek_d DEFINE_THISCALL_WRAPPER(filebuf_setbuf, 12) streambuf* __thiscall filebuf_setbuf(filebuf *this, char *buffer, int length) { - FIXME("(%p %p %d) stub\n", this, buffer, length); - return NULL; + streambuf *ret; + + TRACE("(%p %p %d)\n", this, buffer, length); + if (this->base.base != NULL) + return NULL; + + streambuf_lock(&this->base); + ret = streambuf_setbuf(&this->base, buffer, length); + streambuf_unlock(&this->base); + return ret; }
/* ?setmode@filebuf@@QAEHH@Z */ diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index 5a58dfd..559bee0 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -158,6 +158,7 @@ static filebuf* (*__thiscall p_filebuf_attach)(filebuf*, filedesc); static filebuf* (*__thiscall p_filebuf_open)(filebuf*, const char*, ios_open_mode, int); static filebuf* (*__thiscall p_filebuf_close)(filebuf*); static int (*__thiscall p_filebuf_setmode)(filebuf*, int); +static streambuf* (*__thiscall p_filebuf_setbuf)(filebuf*, char*, int);
/* ios */ static ios* (*__thiscall p_ios_copy_ctor)(ios*, const ios*); @@ -297,6 +298,7 @@ static BOOL init(void) SET(p_filebuf_open, "?open@filebuf@@QEAAPEAV1@PEBDHH@Z"); SET(p_filebuf_close, "?close@filebuf@@QEAAPEAV1@XZ"); SET(p_filebuf_setmode, "?setmode@filebuf@@QEAAHH@Z"); + SET(p_filebuf_setbuf, "?setbuf@filebuf@@UEAAPEAVstreambuf@@PEADH@Z");
SET(p_ios_copy_ctor, "??0ios@@IEAA@AEBV0@@Z"); SET(p_ios_ctor, "??0ios@@IEAA@XZ"); @@ -356,6 +358,7 @@ static BOOL init(void) SET(p_filebuf_open, "?open@filebuf@@QAEPAV1@PBDHH@Z"); SET(p_filebuf_close, "?close@filebuf@@QAEPAV1@XZ"); SET(p_filebuf_setmode, "?setmode@filebuf@@QAEHH@Z"); + SET(p_filebuf_setbuf, "?setbuf@filebuf@@UAEPAVstreambuf@@PADH@Z");
SET(p_ios_copy_ctor, "??0ios@@IAE@ABV0@@Z"); SET(p_ios_ctor, "??0ios@@IAE@XZ"); @@ -997,6 +1000,33 @@ static void test_filebuf(void) ok(thread != NULL, "CreateThread failed\n"); WaitForSingleObject(lock_arg.lock, INFINITE);
+ /* setbuf */ + fb1.base.do_lock = 0; + pret = (filebuf*) call_func3(p_filebuf_setbuf, &fb1, read_buffer, 16); + ok(pret == &fb1, "wrong return, expected %p got %p\n", &fb1, pret); + ok(fb1.base.allocated == 0, "wrong allocate value, expected 0 got %d\n", fb1.base.allocated); + ok(fb1.base.base == read_buffer, "wrong buffer, expected %p got %p\n", read_buffer, fb1.base.base); + ok(fb1.base.pbase == NULL, "wrong put area, expected %p got %p\n", NULL, fb1.base.pbase); + fb1.base.pbase = fb1.base.pptr = fb1.base.base; + fb1.base.epptr = fb1.base.ebuf; + fb1.base.do_lock = -1; + pret = (filebuf*) call_func3(p_filebuf_setbuf, &fb1, read_buffer, 16); + ok(pret == NULL, "wrong return, expected %p got %p\n", NULL, pret); + ok(fb1.base.allocated == 0, "wrong allocate value, expected 0 got %d\n", fb1.base.allocated); + ok(fb1.base.base == read_buffer, "wrong buffer, expected %p got %p\n", read_buffer, fb1.base.base); + ok(fb1.base.pbase == read_buffer, "wrong put area, expected %p got %p\n", read_buffer, fb1.base.pbase); + fb1.base.base = fb1.base.ebuf = NULL; + fb1.base.do_lock = 0; + pret = (filebuf*) call_func3(p_filebuf_setbuf, &fb1, read_buffer, 0); + ok(pret == &fb1, "wrong return, expected %p got %p\n", &fb1, pret); + ok(fb1.base.allocated == 0, "wrong allocate value, expected 0 got %d\n", fb1.base.allocated); + ok(fb1.base.unbuffered == 1, "wrong unbuffered value, expected 1 got %d\n", fb1.base.unbuffered); + ok(fb1.base.base == NULL, "wrong buffer, expected %p got %p\n", NULL, fb1.base.base); + ok(fb1.base.pbase == read_buffer, "wrong put area, expected %p got %p\n", read_buffer, fb1.base.pbase); + fb1.base.pbase = fb1.base.pptr = fb1.base.epptr = NULL; + fb1.base.unbuffered = 0; + fb1.base.do_lock = -1; + /* attach */ pret = (filebuf*) call_func2(p_filebuf_attach, &fb1, 2); ok(pret == NULL, "wrong return, expected %p got %p\n", NULL, pret);