Michael Karcher : msvcrt/file: stdio should clamp characters to 8 bits.
Alexandre Julliard
julliard at winehq.org
Tue Aug 19 08:46:35 CDT 2008
Module: wine
Branch: master
Commit: 5f2159e806a751aa42fcb5495556484b4aa66242
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5f2159e806a751aa42fcb5495556484b4aa66242
Author: Michael Karcher <wine at mkarcher.dialup.fu-berlin.de>
Date: Sat Aug 16 17:08:51 2008 +0200
msvcrt/file: stdio should clamp characters to 8 bits.
---
dlls/msvcrt/file.c | 4 +-
dlls/msvcrt/tests/file.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index cd15e40..c78e46c 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -2539,7 +2539,7 @@ int CDECL MSVCRT_fputc(int c, MSVCRT_FILE* file)
return res ? res : c;
}
else
- return c;
+ return c & 0xff;
} else {
return MSVCRT__flsbuf(c, file);
}
@@ -2568,7 +2568,7 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
unsigned char cc=c;
int len;
len = MSVCRT__write(file->_file, &cc, 1);
- if (len == 1) return c;
+ if (len == 1) return c & 0xff;
file->_flag |= MSVCRT__IOERR;
return MSVCRT_EOF;
}
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index ec22d81..45ffdce 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -334,6 +334,63 @@ static void test_fgetc( void )
unlink(tempf);
}
+static void test_fputc( void )
+{
+ char* tempf;
+ FILE *tempfh;
+ int ret;
+
+ tempf=_tempnam(".","wne");
+ tempfh = fopen(tempf,"wb");
+ ret = fputc(0,tempfh);
+ ok(0 == ret, "fputc(0,tempfh) expected %x got %x\n", 0, ret);
+ ret = fputc(0xff,tempfh);
+ ok(0xff == ret, "fputc(0xff,tempfh) expected %x got %x\n", 0xff, ret);
+ ret = fputc(0xffffffff,tempfh);
+ ok(0xff == ret, "fputc(0xffffffff,tempfh) expected %x got %x\n", 0xff, ret);
+ fclose(tempfh);
+
+ tempfh = fopen(tempf,"rb");
+ ret = fputc(0,tempfh);
+ ok(EOF == ret, "fputc(0,tempfh) on r/o file expected %x got %x\n", EOF, ret);
+ fclose(tempfh);
+
+ unlink(tempf);
+}
+
+static void test_flsbuf( void )
+{
+ char* tempf;
+ FILE *tempfh;
+ int ret;
+ int bufmode;
+ int bufmodes[] = {_IOFBF,_IONBF};
+
+ tempf=_tempnam(".","wne");
+ for (bufmode=0; bufmode < sizeof(bufmodes)/sizeof(bufmodes[0]); bufmode++)
+ {
+ tempfh = fopen(tempf,"wb");
+ setvbuf(tempfh,NULL,bufmodes[bufmode],2048);
+ ret = _flsbuf(0,tempfh);
+ ok(0 == ret, "_flsbuf(0,tempfh) with bufmode %x expected %x got %x\n",
+ bufmodes[bufmode], 0, ret);
+ ret = _flsbuf(0xff,tempfh);
+ ok(0xff == ret, "_flsbuf(0xff,tempfh) with bufmode %x expected %x got %x\n",
+ bufmodes[bufmode], 0, ret);
+ ret = _flsbuf(0xffffffff,tempfh);
+ ok(0xff == ret, "_flsbuf(0xffffffff,tempfh) with bufmode %x expected %x got %x\n",
+ bufmodes[bufmode], 0, ret);
+ fclose(tempfh);
+ }
+
+ tempfh = fopen(tempf,"rb");
+ ret = _flsbuf(0,tempfh);
+ ok(EOF == ret, "_flsbuf(0,tempfh) on r/o file expected %x got %x\n", EOF, ret);
+ fclose(tempfh);
+
+ unlink(tempf);
+}
+
static void test_fgetwc( void )
{
#define LLEN 512
@@ -1061,6 +1118,8 @@ START_TEST(file)
test_readmode(FALSE); /* binary mode */
test_readmode(TRUE); /* ascii mode */
test_fgetc();
+ test_fputc();
+ test_flsbuf();
test_fgetwc();
test_ctrlz();
test_file_put_get();
More information about the wine-cvs
mailing list