New module 'fseek'.
authorBruno Haible <bruno@clisp.org>
Mon, 28 May 2007 14:48:52 +0000 (14:48 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 28 May 2007 14:48:52 +0000 (14:48 +0000)
ChangeLog
lib/fseek.c [new file with mode: 0644]
lib/stdio_.h
m4/fseek.m4 [new file with mode: 0644]
m4/stdio_h.m4
modules/fseek [new file with mode: 0644]
modules/stdio

index b1eabf7..74a1047 100644 (file)
--- 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 (file)
index 0000000..4afa0db
--- /dev/null
@@ -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);
+}
index a8290ac..da3ed0d 100644 (file)
@@ -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 (file)
index 0000000..80e4501
--- /dev/null
@@ -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
+])
index 2cddcc3..43e9683 100644 (file)
@@ -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 (file)
index 0000000..07f948e
--- /dev/null
@@ -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
+
index c8a4623..ac9b74b 100644 (file)
@@ -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)' \