summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-02-22 05:11:26 +0000
committerUlrich Drepper <drepper@redhat.com>2002-02-22 05:11:26 +0000
commit903b3396b8a1a5f4488649b7975cffed4c771e80 (patch)
treeb195ff95e470db62038e0fafa4595116791189ea
parent15e260e8e0b7f046f68275a1e1516561a516a0ee (diff)
downloadglibc-903b3396b8a1a5f4488649b7975cffed4c771e80.tar.gz
glibc-903b3396b8a1a5f4488649b7975cffed4c771e80.tar.xz
glibc-903b3396b8a1a5f4488649b7975cffed4c771e80.zip
Update.
2002-02-21  Jakub Jelinek  <jakub@redhat.com>

	* libio/fileops.c (_IO_file_seekoff_mmap): Fix fseek SEEK_END.
	* stdio-common/tst-fseek.c (main): Add test for this.
-rw-r--r--ChangeLog5
-rw-r--r--libio/fileops.c2
-rw-r--r--stdio-common/tst-fseek.c63
3 files changed, 69 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 23f5813287..0cd1271d5c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-02-21  Jakub Jelinek  <jakub@redhat.com>
+
+	* libio/fileops.c (_IO_file_seekoff_mmap): Fix fseek SEEK_END.
+	* stdio-common/tst-fseek.c (main): Add test for this.
+
 2002-02-19  Ulrich Drepper  <drepper@redhat.com.>
 
 	* stdlib/Versions: Move __on_exit to GLIBC_PRIVATE.
diff --git a/libio/fileops.c b/libio/fileops.c
index 37c47eef89..0d02fca93e 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -880,7 +880,7 @@ _IO_file_seekoff_mmap (fp, offset, dir, mode)
     case _IO_seek_set:
       break;
     case _IO_seek_end:
-      offset = fp->_IO_read_end - fp->_IO_read_base + offset;
+      offset += fp->_IO_buf_end - fp->_IO_buf_base;
       break;
     }
   /* At this point, dir==_IO_seek_set. */
diff --git a/stdio-common/tst-fseek.c b/stdio-common/tst-fseek.c
index 79eef97b62..243dcd35a7 100644
--- a/stdio-common/tst-fseek.c
+++ b/stdio-common/tst-fseek.c
@@ -419,6 +419,69 @@ main (void)
       result = 1;
     }
 
+  fclose (fp);
+
+#ifdef USE_IN_LIBIO
+  fp = fopen (fname, "r");
+  if (fp == NULL)
+    {
+      puts ("fopen() failed\n");
+      result = 1;
+    }
+  else if (fstat64 (fileno (fp), &st1) < 0)
+    {
+      puts ("fstat64() before fseeko() failed\n");
+      result = 1;
+    }
+  else if (fseeko (fp, 0, SEEK_END) != 0)
+    {
+      puts ("fseeko(fp, 0, SEEK_END) failed");
+      result = 1;
+    }
+  else if (ftello (fp) != st1.st_size)
+    {
+      printf ("fstat64 st_size %zd ftello %zd\n", st1.st_size,
+	      ftello (fp));
+      result = 1;
+    }
+  else
+    puts ("SEEK_END works");
+  if (fp != NULL)
+    fclose (fp);
+
+  fp = fopen (fname, "r");
+  if (fp == NULL)
+    {
+      puts ("fopen() failed\n");
+      result = 1;
+    }
+  else if (fstat64 (fileno (fp), &st1) < 0)
+    {
+      puts ("fstat64() before fgetc() failed\n");
+      result = 1;
+    }
+  else if (fgetc (fp) == EOF)
+    {
+      puts ("fgetc() before fseeko() failed\n");
+      result = 1;
+    }
+  else if (fseeko (fp, 0, SEEK_END) != 0)
+    {
+      puts ("fseeko(fp, 0, SEEK_END) failed");
+      result = 1;
+    }
+  else if (ftello (fp) != st1.st_size)
+    {
+      printf ("fstat64 st_size %zd ftello %zd\n", st1.st_size,
+	      ftello (fp));
+      result = 1;
+    }
+  else
+    puts ("SEEK_END works");
+  if (fp != NULL)
+    fclose (fp);
+#endif
+
  out:
   unlink (fname);