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

Alexandre Julliard julliard at winehq.org
Thu Jan 29 09:14:53 CST 2009


Module: wine
Branch: master
Commit: 7f3c70c52fe470d431a51b3363ed4f7336d5f7f5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7f3c70c52fe470d431a51b3363ed4f7336d5f7f5

Author: Dan Kegel <dank at kegel.com>
Date:   Wed Jan 28 21:51:59 2009 -0800

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

---

 dlls/msvcrt/file.c       |    8 ++++++++
 dlls/msvcrt/tests/file.c |   38 ++++++++++++++++++--------------------
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 2740cfa..30f83e6 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<file->_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 3c8844b..1a524fc 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");




More information about the wine-cvs mailing list