changeset 8888:6f9096a04fe8

New module 'ftell'.
author Bruno Haible <bruno@clisp.org>
date Mon, 28 May 2007 15:13:36 +0000
parents 42187fcef367
children 4f3e993d4155
files ChangeLog doc/functions/ftell.texi lib/ftell.c lib/stdio_.h m4/ftell.m4 m4/stdio_h.m4 modules/ftell modules/stdio
diffstat 8 files changed, 112 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2007-05-28  Bruno Haible  <bruno@clisp.org>
+
+	* lib/ftell.c: New file.
+	* modules/ftell: New file.
+	* m4/ftell.m4: New file.
+	* doc/functions/ftell.texi: Update.
+	* m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Set also GNULIB_FTELL,
+	REPLACE_FTELL.
+	* lib/stdio_.h (rpl_ftell): New declaration.
+	* modules/stdio (Makefile.am): Substitute also GNULIB_FTELL,
+	REPLACE_FTELL.
+
 2007-05-28  Eric Blake  <ebb9@byu.net>
 
 	* lib/allocsa.h (safe_alloca): Avoid compiler warning.
--- a/doc/functions/ftell.texi
+++ b/doc/functions/ftell.texi
@@ -4,12 +4,12 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/ftell.html}
 
-Gnulib module: ftello
+Gnulib module: ftell
 
 Portability problems fixed by Gnulib:
 @itemize
 @item
-This function mistakenly succeeds on non-seekable files: mingw.
+This function mistakenly succeeds on pipes on some platforms: mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
new file mode 100644
--- /dev/null
+++ b/lib/ftell.c
@@ -0,0 +1,39 @@
+/* An ftell() function that works around platform bugs.
+   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>
+
+#include <errno.h>
+/* Get off_t.  */
+#include <unistd.h>
+
+long
+ftell (FILE *fp)
+{
+  /* Use the replacement ftello function with all its workarounds.  */
+  off_t offset = ftello (fp);
+  if (offset == (long)offset)
+    return (long)offset;
+  else
+    {
+      errno = EOVERFLOW;
+      return -1;
+    }
+}
--- a/lib/stdio_.h
+++ b/lib/stdio_.h
@@ -268,7 +268,19 @@
     ftello (f))
 #endif
 
-#if defined GNULIB_POSIXCHECK
+#if @GNULIB_FTELL@ && @REPLACE_FTELL@
+extern long rpl_ftell (FILE *fp);
+# undef ftell
+# if GNULIB_POSIXCHECK
+#  define ftell(f) \
+     (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
+                       "on 32-bit platforms - " \
+                       "use ftello function for handling of large files"), \
+      rpl_ftell (f))
+# else
+#  define ftell rpl_ftell
+# endif
+#elif defined GNULIB_POSIXCHECK
 # ifndef ftell
 #  define ftell(f) \
      (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
new file mode 100644
--- /dev/null
+++ b/m4/ftell.m4
@@ -0,0 +1,16 @@
+# ftell.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_FTELL],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_TELLO])
+  dnl When ftello needs fixes, ftell needs them too.
+  if test $REPLACE_FTELLO != 0; then
+    AC_LIBOBJ([ftell])
+    REPLACE_FTELL=1
+  fi
+])
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -32,6 +32,7 @@
   GNULIB_VASPRINTF=0;      AC_SUBST([GNULIB_VASPRINTF])
   GNULIB_FSEEK=0;          AC_SUBST([GNULIB_FSEEK])
   GNULIB_FSEEKO=0;         AC_SUBST([GNULIB_FSEEKO])
+  GNULIB_FTELL=0;          AC_SUBST([GNULIB_FTELL])
   GNULIB_FTELLO=0;         AC_SUBST([GNULIB_FTELLO])
   GNULIB_FFLUSH=0;         AC_SUBST([GNULIB_FFLUSH])
   dnl Assume proper GNU behavior unless another module says otherwise.
@@ -52,6 +53,7 @@
   REPLACE_FSEEK=0;         AC_SUBST([REPLACE_FSEEK])
   HAVE_FTELLO=1;           AC_SUBST([HAVE_FTELLO])
   REPLACE_FTELLO=0;        AC_SUBST([REPLACE_FTELLO])
+  REPLACE_FTELL=0;         AC_SUBST([REPLACE_FTELL])
   REPLACE_FFLUSH=0;        AC_SUBST([REPLACE_FFLUSH])
 ])
 
new file mode 100644
--- /dev/null
+++ b/modules/ftell
@@ -0,0 +1,26 @@
+Description:
+ftell() function: Retrieve the position of a FILE stream.
+
+Files:
+lib/ftell.c
+m4/ftell.m4
+
+Depends-on:
+ftello
+stdio
+
+configure.ac:
+gl_FUNC_FTELL
+gl_STDIO_MODULE_INDICATOR([ftell])
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
--- a/modules/stdio
+++ b/modules/stdio
@@ -33,6 +33,7 @@
 	      -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
 	      -e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \
 	      -e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \
+	      -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
 	      -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
 	      -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
 	      -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
@@ -50,6 +51,7 @@
 	      -e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \
 	      -e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \
 	      -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
+	      -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \
 	      -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/stdio_.h; \