Eric Blake wrote: > --- doc/functions/ftell.texi 1 May 2007 15:11:38 -0000 1.1 > +++ doc/functions/ftell.texi 24 May 2007 16:21:36 -0000 > @@ -4,10 +4,12 @@ > > POSIX specification: @url{http://www.opengroup.org/susv3xsh/ftell.html} > > -Gnulib module: --- > +Gnulib module: ftello > > Portability problems fixed by Gnulib: > @itemize > [EMAIL PROTECTED] > +This function mistakenly succeeds on non-seekable files: mingw. > @end itemize > > Portability problems not fixed by Gnulib:
Likewise, this requires an 'ftell' module. 2007-05-28 Bruno Haible <[EMAIL PROTECTED]> * 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. =========================== lib/ftell.c ============================== /* 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; } } =========================== modules/ftell ============================ 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 =========================== m4/ftell.m4 ============================== # 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 ]) ====================================================================== *** doc/functions/ftell.texi 28 May 2007 14:08:37 -0000 1.3 --- doc/functions/ftell.texi 28 May 2007 15:08:46 -0000 *************** *** 4,15 **** POSIX specification: @url{http://www.opengroup.org/susv3xsh/ftell.html} ! Gnulib module: ftello Portability problems fixed by Gnulib: @itemize @item ! This function mistakenly succeeds on non-seekable files: mingw. @end itemize Portability problems not fixed by Gnulib: --- 4,15 ---- POSIX specification: @url{http://www.opengroup.org/susv3xsh/ftell.html} ! Gnulib module: ftell Portability problems fixed by Gnulib: @itemize @item ! This function mistakenly succeeds on pipes on some platforms: mingw. @end itemize Portability problems not fixed by Gnulib: *** m4/stdio_h.m4 28 May 2007 14:51:49 -0000 1.15 --- m4/stdio_h.m4 28 May 2007 15:08:46 -0000 *************** *** 32,37 **** --- 32,38 ---- 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,57 **** --- 53,59 ---- 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]) ]) *** lib/stdio_.h 28 May 2007 14:51:49 -0000 1.29 --- lib/stdio_.h 28 May 2007 15:08:46 -0000 *************** *** 268,274 **** ftello (f)) #endif ! #if defined GNULIB_POSIXCHECK # ifndef ftell # define ftell(f) \ (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \ --- 268,286 ---- ftello (f)) #endif ! #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 " \ *** modules/stdio 28 May 2007 14:51:49 -0000 1.17 --- modules/stdio 28 May 2007 15:08:46 -0000 *************** *** 33,38 **** --- 33,39 ---- -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,55 **** --- 51,57 ---- -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; \