bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'fseek' (Re: mingw lseek bug)


From: Bruno Haible
Subject: new module 'fseek' (Re: mingw lseek bug)
Date: Mon, 28 May 2007 17:01:34 +0200
User-agent: KMail/1.5.4

Eric Blake wrote:
> --- doc/functions/fseek.texi  1 May 2007 15:11:38 -0000       1.1
> +++ doc/functions/fseek.texi  24 May 2007 16:21:36 -0000
> @@ -4,10 +4,12 @@
>  
>  POSIX specification: @url{http://www.opengroup.org/susv3xsh/fseek.html}
>  
> -Gnulib module: ---
> +Gnulib module: fseeko
>  
>  Portability problems fixed by Gnulib:
>  @itemize
> address@hidden
> +This function mistakenly succeeds on non-seekable files: mingw.
>  @end itemize
>  
>  Portability problems not fixed by Gnulib:

This makes no sense. You cannot say that the module 'fseeko' provides any
portability fixes to the guy who uses the fseek() function: It redefines
fseeko(), but leaves fseek() alone.

But obviously we _want_ fseek() to reject pipes on mingw. So, what's needed,
is an 'fseek' module. To avoid code duplication between lib/fseek.c and
lib/fseeko.c, let's simply have fseek() call fseeko().

2007-05-28  Bruno Haible  <address@hidden>

        * 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.

============================= lib/fseek.c =============================
/* 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 <config.h>

/* Specification.  */
#include <stdio.h>

/* Get off_t.  */
#include <unistd.h>

int
fseek (FILE *fp, long offset, int whence)
{
  /* Use the replacement fseeko function with all its workarounds.  */
  return fseeko (fp, (off_t)offset, whence);
}
============================= modules/fseek ===========================
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:
<stdio.h>

License:
LGPL

Maintainer:
Bruno Haible

============================= m4/fseek.m4 =============================
# 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
])
=======================================================================
--- doc/functions/fseek.texi    28 May 2007 14:08:37 -0000      1.3
+++ doc/functions/fseek.texi    28 May 2007 14:58:51 -0000
@@ -4,12 +4,12 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/fseek.html}
 
-Gnulib module: fseeko
+Gnulib module: fseek
 
 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:
*** lib/stdio_.h        28 May 2007 13:55:57 -0000      1.28
--- lib/stdio_.h        28 May 2007 14:51:03 -0000
***************
*** 232,238 ****
      fseeko (f, o, w))
  #endif
  
! #if defined GNULIB_POSIXCHECK
  # ifndef fseek
  #  define fseek(f,o,w) \
       (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
--- 232,250 ----
      fseeko (f, o, w))
  #endif
  
! #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 " \
*** m4/stdio_h.m4       24 May 2007 03:53:38 -0000      1.14
--- m4/stdio_h.m4       28 May 2007 14:51:04 -0000
***************
*** 1,4 ****
! # stdio_h.m4 serial 5
  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,
--- 1,4 ----
! # 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,35 ****
--- 30,36 ----
    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,53 ****
--- 49,55 ----
    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])
*** modules/stdio       24 May 2007 16:59:22 -0000      1.16
--- modules/stdio       28 May 2007 14:51:04 -0000
***************
*** 31,36 ****
--- 31,37 ----
              -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,52 ****
--- 48,54 ----
              -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)' \





reply via email to

[Prev in Thread] Current Thread [Next in Thread]