summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-05-28 15:13:36 +0000
committerBruno Haible <bruno@clisp.org>2007-05-28 15:13:36 +0000
commitcf0e9950204657e10ec322126130fb35b1d99925 (patch)
tree4e2855a94f9b6a85c3d11bf0d6f9cb12a1340736
parent8ad1cc5a9cd83e5269203bfbbf9581e93da567b7 (diff)
downloadgnulib-cf0e9950204657e10ec322126130fb35b1d99925.tar.gz
New module 'ftell'.
-rw-r--r--ChangeLog12
-rw-r--r--doc/functions/ftell.texi4
-rw-r--r--lib/ftell.c39
-rw-r--r--lib/stdio_.h14
-rw-r--r--m4/ftell.m416
-rw-r--r--m4/stdio_h.m42
-rw-r--r--modules/ftell26
-rw-r--r--modules/stdio2
8 files changed, 112 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 4b4bfcf6ad..47b74acfdc 100644
--- 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.
diff --git a/doc/functions/ftell.texi b/doc/functions/ftell.texi
index a657ad4735..00b5402dc3 100644
--- 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:
diff --git a/lib/ftell.c b/lib/ftell.c
new file mode 100644
index 0000000000..796e687b60
--- /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;
+ }
+}
diff --git a/lib/stdio_.h b/lib/stdio_.h
index da3ed0d469..df41c2e9b5 100644
--- a/lib/stdio_.h
+++ b/lib/stdio_.h
@@ -268,7 +268,19 @@ extern off_t ftello (FILE *fp);
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 " \
diff --git a/m4/ftell.m4 b/m4/ftell.m4
new file mode 100644
index 0000000000..115638af74
--- /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
+])
diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4
index 43e96835ec..955c91216e 100644
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -32,6 +32,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
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 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
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])
])
diff --git a/modules/ftell b/modules/ftell
new file mode 100644
index 0000000000..1dd2348b95
--- /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
+
diff --git a/modules/stdio b/modules/stdio
index ac9b74bf5e..18c80b4451 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -33,6 +33,7 @@ stdio.h: stdio_.h
-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 @@ stdio.h: stdio_.h
-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; \