diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 2740cfa4315..30f83e66f17 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -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_cnt; i++) { + if (file->_ptr[i] == '\n') + offset--; + } + } } /* Discard buffered input */ file->_cnt = 0; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 3c8844b7bfe..1a524fc3f5c 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -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");