From cab1c5a2da80863739e730225ee4c1842b05e217 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 28 May 2007 14:48:52 +0000 Subject: [PATCH] New module 'fseek'. --- ChangeLog | 12 ++++++++++++ lib/fseek.c | 31 +++++++++++++++++++++++++++++++ lib/stdio_.h | 14 +++++++++++++- m4/fseek.m4 | 16 ++++++++++++++++ m4/stdio_h.m4 | 4 +++- modules/fseek | 26 ++++++++++++++++++++++++++ modules/stdio | 2 ++ 7 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 lib/fseek.c create mode 100644 m4/fseek.m4 create mode 100644 modules/fseek diff --git a/ChangeLog b/ChangeLog index b1eabf737..74a104775 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2007-05-28 Bruno Haible + * 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 + * lib/stdio_.h (fflush): More comments. 2007-05-28 Bruno Haible diff --git a/lib/fseek.c b/lib/fseek.c new file mode 100644 index 000000000..4afa0db8a --- /dev/null +++ b/lib/fseek.c @@ -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 + +/* Specification. */ +#include + +/* Get off_t. */ +#include + +int +fseek (FILE *fp, long offset, int whence) +{ + /* Use the replacement fseeko function with all its workarounds. */ + return fseeko (fp, (off_t)offset, whence); +} diff --git a/lib/stdio_.h b/lib/stdio_.h index a8290ac3a..da3ed0d46 100644 --- a/lib/stdio_.h +++ b/lib/stdio_.h @@ -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 index 000000000..80e450108 --- /dev/null +++ b/m4/fseek.m4 @@ -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 +]) diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 index 2cddcc331..43e96835e 100644 --- a/m4/stdio_h.m4 +++ b/m4/stdio_h.m4 @@ -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 index 000000000..07f948e8e --- /dev/null +++ b/modules/fseek @@ -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: + + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/stdio b/modules/stdio index c8a462373..ac9b74bf5 100644 --- a/modules/stdio +++ b/modules/stdio @@ -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)' \ -- 2.11.0