msvcrt: Remove CRs earlier in ascii mode in fseek, too.

This commit is contained in:
Dan Kegel 2009-01-28 21:51:59 -08:00 committed by Alexandre Julliard
parent 5bf1ae82f1
commit 7f3c70c52f
2 changed files with 26 additions and 20 deletions

View File

@ -910,6 +910,14 @@ int CDECL MSVCRT_fseek(MSVCRT_FILE* file, long offset, int whence)
if(whence == SEEK_CUR && file->_flag & MSVCRT__IOREAD ) {
offset -= file->_cnt;
if (MSVCRT_fdesc[file->_file].wxflag & WX_TEXT) {
/* Black magic correction for CR removal */
int i;
for (i=0; i<file->_cnt; i++) {
if (file->_ptr[i] == '\n')
offset--;
}
}
}
/* Discard buffered input */
file->_cnt = 0;

View File

@ -344,34 +344,32 @@ static void test_asciimode(void)
c= fgetc(fp);
c= fgetc(fp);
fseek(fp,0,SEEK_CUR);
todo_wine {
for(i=1; i<10; i++) {
ok((j = ftell(fp)) == i*3, "ftell fails in TEXT mode\n");
fseek(fp,0,SEEK_CUR);
ok((c = fgetc(fp)) == '0'+ i, "fgetc after fseek failed in line %d\n", i);
c= fgetc(fp);
}
/* Show that fseek doesn't skip \\r !*/
rewind(fp);
for(i=1; i<10; i++) {
ok((j = ftell(fp)) == i*3, "ftell fails in TEXT mode\n");
fseek(fp,0,SEEK_CUR);
ok((c = fgetc(fp)) == '0'+ i, "fgetc after fseek failed in line %d\n", i);
c= fgetc(fp);
}
/* Show that fseek doesn't skip \\r !*/
rewind(fp);
c= fgetc(fp);
fseek(fp, 2 ,SEEK_CUR);
for(i=1; i<10; i++) {
ok((c = fgetc(fp)) == '0'+ i, "fgetc after fseek with pos Offset failed in line %d\n", i);
fseek(fp, 2 ,SEEK_CUR);
for(i=1; i<10; i++) {
ok((c = fgetc(fp)) == '0'+ i, "fgetc after fseek with pos Offset failed in line %d\n", i);
fseek(fp, 2 ,SEEK_CUR);
}
fseek(fp, 9*3 ,SEEK_SET);
c = fgetc(fp);
}
fseek(fp, 9*3 ,SEEK_SET);
c = fgetc(fp);
fseek(fp, -4 ,SEEK_CUR);
for(i= 8; i>=0; i--) {
ok((c = fgetc(fp)) == '0'+ i, "fgetc after fseek with neg Offset failed in line %d\n", i);
fseek(fp, -4 ,SEEK_CUR);
for(i= 8; i>=0; i--) {
ok((c = fgetc(fp)) == '0'+ i, "fgetc after fseek with neg Offset failed in line %d\n", i);
fseek(fp, -4 ,SEEK_CUR);
}
}
/* Show what happens is fseek positions filepointer on \\r */
fclose(fp);
fp = fopen("ascii.tst", "r");
fseek(fp, 3 ,SEEK_SET);
ok((c = fgetc(fp)) == '1', "fgetc fails to read nect char when positioned on \\r \n");
ok((c = fgetc(fp)) == '1', "fgetc fails to read next char when positioned on \\r \n");
fclose(fp);
unlink("ascii.tst");