=?UTF-8?Q?Iv=C3=A1n=20Matellanes=20?=: msvcirt: Implement filebuf:: setmode.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Aug 17 09:01:12 CDT 2015
Module: wine
Branch: master
Commit: 43bb816373e4c1d6fbb581e27f68e1e1bc6df79d
URL: http://source.winehq.org/git/wine.git/?a=commit;h=43bb816373e4c1d6fbb581e27f68e1e1bc6df79d
Author: Iván Matellanes <matellanesivan at gmail.com>
Date: Mon Aug 10 20:09:01 2015 +0200
msvcirt: Implement filebuf::setmode.
---
dlls/msvcirt/msvcirt.c | 16 ++++++++++++----
dlls/msvcirt/tests/msvcirt.c | 25 +++++++++++++++++++++++++
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 7caa05b..83184a0 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -45,9 +45,9 @@ const int filebuf_sh_write = 0xc00;
/* ?openprot at filebuf@@2HB */
const int filebuf_openprot = 420;
/* ?binary at filebuf@@2HB */
-const int filebuf_binary = 0x8000;
+const int filebuf_binary = _O_BINARY;
/* ?text at filebuf@@2HB */
-const int filebuf_text = 0x4000;
+const int filebuf_text = _O_TEXT;
/* ?adjustfield at ios@@2JB */
const LONG ios_adjustfield = FLAGS_left | FLAGS_right | FLAGS_internal;
@@ -1010,8 +1010,16 @@ streambuf* __thiscall filebuf_setbuf(filebuf *this, char *buffer, int length)
DEFINE_THISCALL_WRAPPER(filebuf_setmode, 8)
int __thiscall filebuf_setmode(filebuf *this, int mode)
{
- FIXME("(%p %d) stub\n", this, mode);
- return 0;
+ int ret;
+
+ TRACE("(%p %d)\n", this, mode);
+ if (mode != filebuf_text && mode != filebuf_binary)
+ return -1;
+
+ streambuf_lock(&this->base);
+ ret = (call_streambuf_sync(&this->base) == EOF) ? -1 : _setmode(this->fd, mode);
+ streambuf_unlock(&this->base);
+ return ret;
}
/* ?sync at filebuf@@UAEHXZ */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 0977173..5a58dfd 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <windef.h>
@@ -65,6 +66,8 @@ const int filebuf_sh_none = 0x800;
const int filebuf_sh_read = 0xa00;
const int filebuf_sh_write = 0xc00;
const int filebuf_openprot = 420;
+const int filebuf_binary = _O_BINARY;
+const int filebuf_text = _O_TEXT;
/* class streambuf */
typedef struct {
@@ -154,6 +157,7 @@ static void (*__thiscall p_filebuf_dtor)(filebuf*);
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);
/* ios */
static ios* (*__thiscall p_ios_copy_ctor)(ios*, const ios*);
@@ -292,6 +296,7 @@ static BOOL init(void)
SET(p_filebuf_attach, "?attach at filebuf@@QEAAPEAV1 at H@Z");
SET(p_filebuf_open, "?open at filebuf@@QEAAPEAV1 at PEBDHH@Z");
SET(p_filebuf_close, "?close at filebuf@@QEAAPEAV1 at XZ");
+ SET(p_filebuf_setmode, "?setmode at filebuf@@QEAAHH at Z");
SET(p_ios_copy_ctor, "??0ios@@IEAA at AEBV0@@Z");
SET(p_ios_ctor, "??0ios@@IEAA at XZ");
@@ -350,6 +355,7 @@ static BOOL init(void)
SET(p_filebuf_attach, "?attach at filebuf@@QAEPAV1 at H@Z");
SET(p_filebuf_open, "?open at filebuf@@QAEPAV1 at PBDHH@Z");
SET(p_filebuf_close, "?close at filebuf@@QAEPAV1 at XZ");
+ SET(p_filebuf_setmode, "?setmode at filebuf@@QAEHH at Z");
SET(p_ios_copy_ctor, "??0ios@@IAE at ABV0@@Z");
SET(p_ios_ctor, "??0ios@@IAE at XZ");
@@ -957,6 +963,7 @@ static void test_filebuf(void)
const char filename2[] = "test2";
const char filename3[] = "test3";
char read_buffer[16];
+ int ret;
memset(&fb1, 0xab, sizeof(filebuf));
memset(&fb2, 0xab, sizeof(filebuf));
@@ -1106,6 +1113,24 @@ static void test_filebuf(void)
ok(pret == NULL, "wrong return, expected %p got %p\n", NULL, pret);
fb3.base.do_lock = -1;
+ /* setmode */
+ fb1.base.do_lock = 0;
+ fb1.base.pbase = fb1.base.pptr = fb1.base.base;
+ fb1.base.epptr = fb1.base.ebuf;
+ ret = (int) call_func2(p_filebuf_setmode, &fb1, filebuf_binary);
+ ok(ret == filebuf_text, "wrong return, expected %d got %d\n", filebuf_text, ret);
+todo_wine
+ ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr);
+ ret = (int) call_func2(p_filebuf_setmode, &fb1, filebuf_binary);
+ ok(ret == filebuf_binary, "wrong return, expected %d got %d\n", filebuf_binary, ret);
+ fb1.base.do_lock = -1;
+ ret = (int) call_func2(p_filebuf_setmode, &fb1, 0x9000);
+ ok(ret == -1, "wrong return, expected -1 got %d\n", ret);
+ fb2.base.do_lock = 0;
+ ret = (int) call_func2(p_filebuf_setmode, &fb2, filebuf_text);
+ ok(ret == -1, "wrong return, expected -1 got %d\n", ret);
+ fb2.base.do_lock = -1;
+
/* close */
pret = (filebuf*) call_func1(p_filebuf_close, &fb2);
ok(pret == NULL, "wrong return, expected %p got %p\n", NULL, pret);
More information about the wine-cvs
mailing list