[3/4] msvcirt: Implement filebuf::setmode

Iván Matellanes matellanesivan at gmail.com
Wed Aug 5 13:32:43 CDT 2015


---
 dlls/msvcirt/msvcirt.c       | 12 ++++++++++--
 dlls/msvcirt/tests/msvcirt.c | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index bf89650..0f82f30 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -1009,8 +1009,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 previous;
+
+    TRACE("(%p %d)\n", this, mode);
+    if (mode != filebuf_text && mode != filebuf_binary)
+        return -1;
+
+    streambuf_lock(&this->base);
+    previous = _setmode(this->fd, mode);
+    streambuf_unlock(&this->base);
+    return previous;
 }
 
 /* ?sync at filebuf@@UAEHXZ */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index e0bda56..ea1e6cb 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -65,6 +65,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 = 0x8000;
+const int filebuf_text = 0x4000;
 
 /* class streambuf */
 typedef struct {
@@ -154,6 +156,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 +295,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 +354,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 +962,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));
@@ -1104,6 +1110,20 @@ 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;
+    ret = (int) call_func2(p_filebuf_setmode, &fb1, filebuf_binary);
+    ok(ret == filebuf_text, "wrong return, expected %d got %d\n", filebuf_text, ret);
+    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);
-- 
2.1.4




More information about the wine-patches mailing list