summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-11-07 16:03:38 -0700
committerEric Blake <ebb9@byu.net>2009-11-07 16:12:53 -0700
commit7becd9d708425924f3a402fdd3c6e18ba2a7e4e3 (patch)
treef091b94b054f7e0959c6cedb1d3f029e039fa00c
parent453d6be7ea3ca6792fd28a71ccc0f1107a9239a4 (diff)
downloadgnulib-7becd9d708425924f3a402fdd3c6e18ba2a7e4e3.tar.gz
fflush, freadseek: use fseeko, not fseek
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>
-rw-r--r--ChangeLog18
-rw-r--r--lib/fflush.c4
-rw-r--r--lib/freadseek.c2
-rw-r--r--modules/freadseek1
-rw-r--r--modules/fseek1
-rw-r--r--tests/test-fflush.c2
-rw-r--r--tests/test-fpurge.c6
-rw-r--r--tests/test-freadable.c8
-rw-r--r--tests/test-freading.c6
-rw-r--r--tests/test-fseeko.c6
-rw-r--r--tests/test-ftell.c6
-rw-r--r--tests/test-ftello.c6
-rw-r--r--tests/test-fwritable.c8
-rw-r--r--tests/test-fwriting.c8
14 files changed, 75 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 997a759ee7..c9d05ad3b6 100644
--- 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.
diff --git a/lib/fflush.c b/lib/fflush.c
index 7c6085cfd8..0af17034e4 100644
--- a/lib/fflush.c
+++ b/lib/fflush.c
@@ -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
}
diff --git a/lib/freadseek.c b/lib/freadseek.c
index 23046fa4c4..fc50f5136d 100644
--- a/lib/freadseek.c
+++ b/lib/freadseek.c
@@ -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
{
diff --git a/modules/freadseek b/modules/freadseek
index 6a920ee80e..e1ad31cb05 100644
--- a/modules/freadseek
+++ b/modules/freadseek
@@ -9,6 +9,7 @@ lib/stdio-impl.h
Depends-on:
freadahead
freadptr
+fseeko
lseek
configure.ac:
diff --git a/modules/fseek b/modules/fseek
index 07f948e8e1..375a54cc53 100644
--- a/modules/fseek
+++ b/modules/fseek
@@ -11,6 +11,7 @@ stdio
configure.ac:
gl_FUNC_FSEEK
+gl_MODULE_INDICATOR([fseek])
gl_STDIO_MODULE_INDICATOR([fseek])
Makefile.am:
diff --git a/tests/test-fflush.c b/tests/test-fflush.c
index 3a17f8d475..3afdf7bd69 100644
--- a/tests/test-fflush.c
+++ b/tests/test-fflush.c
@@ -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);
diff --git a/tests/test-fpurge.c b/tests/test-fpurge.c
index 319a040426..2197b89df6 100644
--- a/tests/test-fpurge.c
+++ b/tests/test-fpurge.c
@@ -23,6 +23,12 @@
#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 \
{ \
diff --git a/tests/test-freadable.c b/tests/test-freadable.c
index 4264cce337..52a328730d 100644
--- a/tests/test-freadable.c
+++ b/tests/test-freadable.c
@@ -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
@@ -23,6 +23,12 @@
#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 \
{ \
diff --git a/tests/test-freading.c b/tests/test-freading.c
index 0f8e686eaa..dfa5ffbf5a 100644
--- a/tests/test-freading.c
+++ b/tests/test-freading.c
@@ -23,6 +23,12 @@
#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 \
{ \
diff --git a/tests/test-fseeko.c b/tests/test-fseeko.c
index 9c284da500..93b0adc361 100644
--- a/tests/test-fseeko.c
+++ b/tests/test-fseeko.c
@@ -21,6 +21,12 @@
#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 \
{ \
diff --git a/tests/test-ftell.c b/tests/test-ftell.c
index 71f3ed26d5..786a448c11 100644
--- a/tests/test-ftell.c
+++ b/tests/test-ftell.c
@@ -23,6 +23,12 @@
#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 \
{ \
diff --git a/tests/test-ftello.c b/tests/test-ftello.c
index d3401ee419..c5b1246ff3 100644
--- a/tests/test-ftello.c
+++ b/tests/test-ftello.c
@@ -23,6 +23,12 @@
#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 \
{ \
diff --git a/tests/test-fwritable.c b/tests/test-fwritable.c
index 6a7b6f007c..a0659edc0c 100644
--- a/tests/test-fwritable.c
+++ b/tests/test-fwritable.c
@@ -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
@@ -23,6 +23,12 @@
#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 \
{ \
diff --git a/tests/test-fwriting.c b/tests/test-fwriting.c
index f2ae068a25..9916b82292 100644
--- a/tests/test-fwriting.c
+++ b/tests/test-fwriting.c
@@ -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
@@ -23,6 +23,12 @@
#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 \
{ \