fflush, freadseek: use fseeko, not fseek
authorEric Blake <ebb9@byu.net>
Sat, 7 Nov 2009 23:03:38 +0000 (16:03 -0700)
committerEric Blake <ebb9@byu.net>
Sat, 7 Nov 2009 23:12:53 +0000 (16:12 -0700)
Follow our own advice: fseek is not safe to use on large files.

* lib/fflush.c (clear_ungetc_buffer_preserving_position)
(clear_ungetc_buffer): Avoid potential problems on large files.
* lib/freadseek.c (freadseek): Likewise.
* modules/freadseek (Depends-on): Add fseeko.
* modules/fseek (configure.ac): Set a witness.
* tests/test-fflush.c (main): Use fseeko.
* tests/test-fpurge.c (fseek): Disable link warning.
* tests/test-freadable.c (fseek): Likewise.
* tests/test-freading.c (fseek): Likewise.
* tests/test-fseeko.c (fseek): Likewise.
* tests/test-ftell.c (fseek): Likewise.
* tests/test-ftello.c (fseek): Likewise.
* tests/test-fwritable.c (fseek): Likewise.
* tests/test-fwriting.c (fseek): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
14 files changed:
ChangeLog
lib/fflush.c
lib/freadseek.c
modules/freadseek
modules/fseek
tests/test-fflush.c
tests/test-fpurge.c
tests/test-freadable.c
tests/test-freading.c
tests/test-fseeko.c
tests/test-ftell.c
tests/test-ftello.c
tests/test-fwritable.c
tests/test-fwriting.c

index 997a759ee7f468fc1348262dfe82a80a78ff6399..c9d05ad3b63c5cfe94b5ba037b805a2361c88b9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-11-07  Eric Blake  <ebb9@byu.net>
+
+       fflush, freadseek: use fseeko, not fseek
+       * lib/fflush.c (clear_ungetc_buffer_preserving_position)
+       (clear_ungetc_buffer): Avoid potential problems on large files.
+       * lib/freadseek.c (freadseek): Likewise.
+       * modules/freadseek (Depends-on): Add fseeko.
+       * modules/fseek (configure.ac): Set a witness.
+       * tests/test-fflush.c (main): Use fseeko.
+       * tests/test-fpurge.c (fseek): Disable link warning.
+       * tests/test-freadable.c (fseek): Likewise.
+       * tests/test-freading.c (fseek): Likewise.
+       * tests/test-fseeko.c (fseek): Likewise.
+       * tests/test-ftell.c (fseek): Likewise.
+       * tests/test-ftello.c (fseek): Likewise.
+       * tests/test-fwritable.c (fseek): Likewise.
+       * tests/test-fwriting.c (fseek): Likewise.
+
 2009-11-06  Simon Josefsson  <simon@josefsson.org>
 
        * modules/memchr (Depends-on): Drop getpagesize dependency.
index 7c6085cfd8725acaf1dfa6d757a5f6e7a9e369ef..0af17034e42c69ad4d51417b06bcd1b2a9b693b2 100644 (file)
@@ -39,7 +39,7 @@ clear_ungetc_buffer_preserving_position (FILE *fp)
 {
   if (fp->_flags & _IO_IN_BACKUP)
     /* _IO_free_backup_area is a bit complicated.  Simply call fseek.  */
-    fseek (fp, 0, SEEK_CUR);
+    fseeko (fp, 0, SEEK_CUR);
 }
 
 #else
@@ -63,7 +63,7 @@ clear_ungetc_buffer (FILE *fp)
 # elif defined _IOERR               /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
   /* Nothing to do.  */
 # else                              /* other implementations */
-  fseek (fp, 0, SEEK_CUR);
+  fseeko (fp, 0, SEEK_CUR);
 # endif
 }
 
index 23046fa4c400a89f23a8e49368427146f079b1bf..fc50f5136d14f76cbea98805d340a43baaedea3d 100644 (file)
@@ -106,7 +106,7 @@ freadseek (FILE *fp, size_t offset)
   if (fd >= 0 && lseek (fd, 0, SEEK_CUR) >= 0)
     {
       /* FP refers to a regular file.  fseek is most efficient in this case.  */
-      return fseek (fp, offset, SEEK_CUR);
+      return fseeko (fp, offset, SEEK_CUR);
     }
   else
     {
index 6a920ee80eb6d7c988747787cbbc276816e31f47..e1ad31cb05e4578a279b56d56d167a323a196ce6 100644 (file)
@@ -9,6 +9,7 @@ lib/stdio-impl.h
 Depends-on:
 freadahead
 freadptr
+fseeko
 lseek
 
 configure.ac:
index 07f948e8e1e91d5cc60d316f1a9efc82dc41f4c9..375a54cc53ed74b367d30e5985bcccd2e44315fc 100644 (file)
@@ -11,6 +11,7 @@ stdio
 
 configure.ac:
 gl_FUNC_FSEEK
+gl_MODULE_INDICATOR([fseek])
 gl_STDIO_MODULE_INDICATOR([fseek])
 
 Makefile.am:
index 3a17f8d475abddac769f852f77bd2202c7a8cf02..3afdf7bd69f93a729fbc3b2000d8973fcfabc2a1 100644 (file)
@@ -59,7 +59,7 @@ main (void)
     }
 #endif
   /* POSIX requires fflush-fseek to set file offset of fd.  */
-  if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0)
+  if (fflush (f) != 0 || fseeko (f, 0, SEEK_CUR) != 0)
     {
       fputs ("Failed to flush-fseek sample file.\n", stderr);
       fclose (f);
index 319a04042691fe8bb073934b51fbe59bfe132165..2197b89df65746d94f18b2960cfcbd1b302c4a8a 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#if !GNULIB_FSEEK
+# undef fseek
+#endif
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
index 4264cce33764c3a0d623df24ad0ded4e208b63a2..52a328730d1372becec31f002a2d0ac49b7ee354 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of freadable() function.
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <stdio.h>
 #include <stdlib.h>
 
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#if !GNULIB_FSEEK
+# undef fseek
+#endif
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
index 0f8e686eaaf9a2c8f71728fd8366ce33e9cab18b..dfa5ffbf5a2a417f4e29516f75d43fceeb27b841 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#if !GNULIB_FSEEK
+# undef fseek
+#endif
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
index 9c284da50061d8b12c64dad672f38a301a38d131..93b0adc3613ea4bb1c7b9a928bb7a41fa860a433 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#if !GNULIB_FSEEK
+# undef fseek
+#endif
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
index 71f3ed26d52545c74cfcb5417ca4cf7ed5d7584b..786a448c1189db48023b57235ecfecce5824e7b8 100644 (file)
 
 #include "binary-io.h"
 
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#if !GNULIB_FSEEK
+# undef fseek
+#endif
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
index d3401ee419aef15e49fa4c797102d9cc4cd19593..c5b1246ff3e1ced20edf31c36194ba4f86e03589 100644 (file)
 
 #include "binary-io.h"
 
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#if !GNULIB_FSEEK
+# undef fseek
+#endif
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
index 6a7b6f007c6236f9ea81c0cf9964b73cb47dc8f7..a0659edc0c4870f460f832d23910ae21b7500b9e 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of fwritable() function.
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <stdio.h>
 #include <stdlib.h>
 
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#if !GNULIB_FSEEK
+# undef fseek
+#endif
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
index f2ae068a25544f8b3461135869a07d26a71c2a9e..9916b822928770b162181da741e461490bfadce6 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of fwriting() function.
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <stdio.h>
 #include <stdlib.h>
 
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#if !GNULIB_FSEEK
+# undef fseek
+#endif
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \