summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-05-28 14:48:52 +0000
committerBruno Haible <bruno@clisp.org>2007-05-28 14:48:52 +0000
commitcab1c5a2da80863739e730225ee4c1842b05e217 (patch)
treeb6f6abe078440c78857e5b773482c3c90670dc6a
parent97c12f59197ed29353e1dde89db3af59bcb3e1ff (diff)
downloadgnulib-cab1c5a2da80863739e730225ee4c1842b05e217.tar.gz
New module 'fseek'.
-rw-r--r--ChangeLog12
-rw-r--r--lib/fseek.c31
-rw-r--r--lib/stdio_.h14
-rw-r--r--m4/fseek.m416
-rw-r--r--m4/stdio_h.m44
-rw-r--r--modules/fseek26
-rw-r--r--modules/stdio2
7 files changed, 103 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b1eabf737a..74a104775a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2007-05-28 Bruno Haible <bruno@clisp.org>
+ * lib/fseek.c: New file.
+ * modules/fseek: New file.
+ * m4/fseek.m4: New file.
+ * doc/functions/fseek.texi: Update.
+ * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Set also GNULIB_FSEEK,
+ REPLACE_FSEEK.
+ * lib/stdio_.h (rpl_fseek): New declaration.
+ * modules/stdio (Makefile.am): Substitute also GNULIB_FSEEK,
+ REPLACE_FSEEK.
+
+2007-05-28 Bruno Haible <bruno@clisp.org>
+
* lib/stdio_.h (fflush): More comments.
2007-05-28 Bruno Haible <bruno@clisp.org>
diff --git a/lib/fseek.c b/lib/fseek.c
new file mode 100644
index 0000000000..4afa0db8ab
--- /dev/null
+++ b/lib/fseek.c
@@ -0,0 +1,31 @@
+/* An fseek() function that, together with fflush(), is POSIX compliant.
+ Copyright (C) 2007 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+/* Get off_t. */
+#include <unistd.h>
+
+int
+fseek (FILE *fp, long offset, int whence)
+{
+ /* Use the replacement fseeko function with all its workarounds. */
+ return fseeko (fp, (off_t)offset, whence);
+}
diff --git a/lib/stdio_.h b/lib/stdio_.h
index a8290ac3a3..da3ed0d469 100644
--- a/lib/stdio_.h
+++ b/lib/stdio_.h
@@ -232,7 +232,19 @@ extern int fseeko (FILE *fp, off_t offset, int whence);
fseeko (f, o, w))
#endif
-#if defined GNULIB_POSIXCHECK
+#if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
+extern int rpl_fseek (FILE *fp, long offset, int whence);
+# undef fseek
+# if defined GNULIB_POSIXCHECK
+# define fseek(f,o,w) \
+ (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
+ "on 32-bit platforms - " \
+ "use fseeko function for handling of large files"), \
+ rpl_fseek (f, o, w))
+# else
+# define fseek rpl_fseek
+# endif
+#elif defined GNULIB_POSIXCHECK
# ifndef fseek
# define fseek(f,o,w) \
(GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
diff --git a/m4/fseek.m4 b/m4/fseek.m4
new file mode 100644
index 0000000000..80e4501083
--- /dev/null
+++ b/m4/fseek.m4
@@ -0,0 +1,16 @@
+# fseek.m4 serial 1
+dnl Copyright (C) 2007 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FSEEK],
+[
+ AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+ AC_REQUIRE([gl_FUNC_FSEEKO])
+ dnl When fseeko needs fixes, fseek needs them too.
+ if test $REPLACE_FSEEKO != 0; then
+ AC_LIBOBJ([fseek])
+ REPLACE_FSEEK=1
+ fi
+])
diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4
index 2cddcc3313..43e96835ec 100644
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 5
+# stdio_h.m4 serial 6
dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -30,6 +30,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF])
GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF])
+ GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK])
GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO])
GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO])
GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH])
@@ -48,6 +49,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF])
HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO])
REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO])
+ REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK])
HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO])
REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
diff --git a/modules/fseek b/modules/fseek
new file mode 100644
index 0000000000..07f948e8e1
--- /dev/null
+++ b/modules/fseek
@@ -0,0 +1,26 @@
+Description:
+fseek() function: Reposition a FILE stream.
+
+Files:
+lib/fseek.c
+m4/fseek.m4
+
+Depends-on:
+fseeko
+stdio
+
+configure.ac:
+gl_FUNC_FSEEK
+gl_STDIO_MODULE_INDICATOR([fseek])
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
diff --git a/modules/stdio b/modules/stdio
index c8a462373b..ac9b74bf5e 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -31,6 +31,7 @@ stdio.h: stdio_.h
-e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
-e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
-e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
+ -e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \
-e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \
-e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
-e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
@@ -47,6 +48,7 @@ stdio.h: stdio_.h
-e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
-e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
-e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \
+ -e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \
-e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
-e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
-e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \