msvcrt/file: stdio should clamp characters to 8 bits.

This commit is contained in:
Michael Karcher 2008-08-16 17:08:51 +02:00 committed by Alexandre Julliard
parent af4562c34d
commit 5f2159e806
2 changed files with 61 additions and 2 deletions

View File

@ -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;
}

View File

@ -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();