msvcrt: Fix fgetwc/s in binary mode.

This commit is contained in:
Duane Clark 2006-07-31 12:15:37 -07:00 committed by Alexandre Julliard
parent d74b6055fe
commit bc194793a7
2 changed files with 32 additions and 14 deletions

View File

@ -2179,14 +2179,32 @@ MSVCRT_wint_t CDECL MSVCRT_fgetwc(MSVCRT_FILE* file)
if (!(MSVCRT_fdesc[file->_file].wxflag & WX_TEXT)) if (!(MSVCRT_fdesc[file->_file].wxflag & WX_TEXT))
{ {
MSVCRT_wchar_t wc; MSVCRT_wchar_t wc;
int r; int i,j;
if ((r = _read(file->_file, &wc, sizeof(wc))) != sizeof(wc)) char *chp, *wcp;
wcp = (char *)&wc;
for(i=0; i<sizeof(wc); i++)
{ {
file->_flag |= (r == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR; if (file->_cnt>0)
{
file->_cnt--;
chp = file->_ptr++;
wcp[i] = *chp;
}
else
{
j = MSVCRT__filbuf(file);
if(file->_cnt<=0)
{
file->_flag |= (file->_cnt == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR;
file->_cnt = 0;
return MSVCRT_WEOF; return MSVCRT_WEOF;
} }
wcp[i] = j;
}
}
return wc; return wc;
} }
c = MSVCRT_fgetc(file); c = MSVCRT_fgetc(file);
if ((*__p___mb_cur_max() > 1) && MSVCRT_isleadbyte(c)) if ((*__p___mb_cur_max() > 1) && MSVCRT_isleadbyte(c))
{ {

View File

@ -329,28 +329,28 @@ static void test_fgetwc( void )
j++; j++;
ok(l==j, "ftell expected %d got %ld\n", j, l); ok(l==j, "ftell expected %d got %ld\n", j, l);
fgetws(wtextW,3,tempfh); fgetws(wtextW,3,tempfh);
todo_wine ok(wtextW[0]=='\r',"expected carriage return got %04hx\n", wtextW[0]); ok(wtextW[0]=='\r',"expected carriage return got %04hx\n", wtextW[0]);
todo_wine ok(wtextW[1]=='\n',"expected newline got %04hx\n", wtextW[1]); ok(wtextW[1]=='\n',"expected newline got %04hx\n", wtextW[1]);
l=ftell(tempfh); l=ftell(tempfh);
j += 4; j += 4;
todo_wine ok(l==j, "ftell expected %d got %ld\n", j, l); ok(l==j, "ftell expected %d got %ld\n", j, l);
for(i=0; i<strlen(mytext); i++) for(i=0; i<strlen(mytext); i++)
wtextW[i] = 0; wtextW[i] = 0;
/* the first time we get the string, it should be entirely within the local buffer */ /* the first time we get the string, it should be entirely within the local buffer */
fgetws(wtextW,LLEN,tempfh); fgetws(wtextW,LLEN,tempfh);
l=ftell(tempfh); l=ftell(tempfh);
j += (strlen(mytext)-1)*sizeof(WCHAR); j += (strlen(mytext)-1)*sizeof(WCHAR);
todo_wine ok(l==j, "ftell expected %d got %ld\n", j, l); ok(l==j, "ftell expected %d got %ld\n", j, l);
diff_found = FALSE; diff_found = FALSE;
aptr = mytextW; aptr = mytextW;
wptr = wtextW; wptr = wtextW;
for (i=0; i<strlen(mytext)-2; i++, aptr++, wptr++) for (i=0; i<strlen(mytext)-2; i++, aptr++, wptr++)
{ {
todo_wine ok(*aptr == *wptr, "Char %d expected %04hx got %04hx\n", i, *aptr, *wptr); ok(*aptr == *wptr, "Char %d expected %04hx got %04hx\n", i, *aptr, *wptr);
diff_found |= (*aptr != *wptr); diff_found |= (*aptr != *wptr);
} }
todo_wine ok(!(diff_found), "fgetwc difference found in BINARY mode\n"); ok(!(diff_found), "fgetwc difference found in BINARY mode\n");
todo_wine ok(*wptr == '\n', "Should get newline\n"); ok(*wptr == '\n', "Should get newline\n");
for(i=0; i<strlen(mytext); i++) for(i=0; i<strlen(mytext); i++)
wtextW[i] = 0; wtextW[i] = 0;
/* the second time we get the string, it should cross the local buffer boundary. /* the second time we get the string, it should cross the local buffer boundary.
@ -361,11 +361,11 @@ static void test_fgetwc( void )
wptr = wtextW; wptr = wtextW;
for (i=0; i<strlen(mytext)-2; i++, aptr++, wptr++) for (i=0; i<strlen(mytext)-2; i++, aptr++, wptr++)
{ {
todo_wine ok(*aptr == *wptr, "Char %d expected %04hx got %04hx\n", i, *aptr, *wptr); ok(*aptr == *wptr, "Char %d expected %04hx got %04hx\n", i, *aptr, *wptr);
diff_found |= (*aptr != *wptr); diff_found |= (*aptr != *wptr);
} }
todo_wine ok(!(diff_found), "fgetwc difference found in BINARY mode\n"); ok(!(diff_found), "fgetwc difference found in BINARY mode\n");
todo_wine ok(*wptr == '\n', "Should get newline\n"); ok(*wptr == '\n', "Should get newline\n");
if(mytextW) free (mytextW); if(mytextW) free (mytextW);
fclose(tempfh); fclose(tempfh);