From cf0e9950204657e10ec322126130fb35b1d99925 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 28 May 2007 15:13:36 +0000 Subject: [PATCH] New module 'ftell'. --- ChangeLog | 12 ++++++++++++ doc/functions/ftell.texi | 4 ++-- lib/ftell.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/stdio_.h | 14 +++++++++++++- m4/ftell.m4 | 16 ++++++++++++++++ m4/stdio_h.m4 | 2 ++ modules/ftell | 26 ++++++++++++++++++++++++++ modules/stdio | 2 ++ 8 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 lib/ftell.c create mode 100644 m4/ftell.m4 create mode 100644 modules/ftell diff --git a/ChangeLog b/ChangeLog index 4b4bfcf6a..47b74acfd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-05-28 Bruno Haible + + * 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 * lib/allocsa.h (safe_alloca): Avoid compiler warning. diff --git a/doc/functions/ftell.texi b/doc/functions/ftell.texi index a657ad473..00b5402dc 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 000000000..796e687b6 --- /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 + +/* Specification. */ +#include + +#include +/* Get off_t. */ +#include + +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 da3ed0d46..df41c2e9b 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 000000000..115638af7 --- /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 43e96835e..955c91216 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 000000000..1dd2348b9 --- /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: + + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/stdio b/modules/stdio index ac9b74bf5..18c80b445 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; \ -- 2.11.0