[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mingw lseek bug
From: |
Eric Blake |
Subject: |
Re: mingw lseek bug |
Date: |
Thu, 24 May 2007 16:49:56 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Eric Blake <ebb9 <at> byu.net> writes:
> > But there are other types of devices as well, such as special character
> > devices (COM: and consoles). It looks safer to include only the regular
> > files:
> > GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_DISK.
>
> At the same time, NUL (corresponding to /dev/null) should appear to be
> seekable, even though it is a character device and is always at position
> 0. Is mingw's fstat reliable enough to get any of this information, or
> does it take native Windows calls like this thread has been suggesting?
I decided that the seekability of NUL doesn't matter (since fflushing NUL is a
effective no-op anyway). So here's the patch I'm checking in; I've tested it
on both cygwin and mingw in isolation, and as part of the followup patch to m4
to use fflush (in fact, it was the m4 patch that I've been sitting on for 2
weeks that drove me to complete this).
2007-05-24 Eric Blake <address@hidden>
Fix lseek on mingw.
* modules/lseek: New module.
* m4/lseek.m4: New file.
* lib/lseek.c: New file.
* modules/lseek-tests: New file.
* tests/test-lseek.c: New file.
* tests/test-lseek.sh: New file.
* MODULES.html.sh: Document lseek module.
* modules/fflush (Depends-on): Add lseek, fseeko.
* modules/fseeko (Depends-on): Likewise.
* modules/ftello (Depends-on): Likewise.
* m4/fseeko.m4 (gl_FUNC_FSEEKO): Replace fseek[o] if lseek is
broken.
* m4/ftello.m4 (gl_FUNC_FTELLO): Replace ftell[o] if lseek is
broken.
* m4/fflush.m4 (gl_REPLACE_FFLUSH): Trigger fseeko module.
* lib/fseeko.c (rpl_fseeko): Quit early on non-seekable files.
* lib/ftello.c (rpl_ftello): Likewise.
* tests/test-fseeko.c (main): Test this.
* tests/test-fseeko.sh: Likewise.
* tests/test-ftello.c (main): Likewise.
* tests/test-ftello.sh: Likewise.
* lib/stdio_.h (fseek, ftell): Simplify, since missing fseeko now
implies replacing fseek.
* modules/stdio (Makefile.am): No longer need HAVE_FSEEKO,
HAVE_FTELLO.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add lseek info.
* modules/unistd (Makefile.am): Likewise.
* lib/unistd_.h (lseek): Declare a replacement.
* doc/functions/lseek.texi (lseek): Document this fix.
* doc/functions/fseek.texi (fseek): Likewise.
* doc/functions/ftell.texi (ftell): Likewise.
Index: MODULES.html.sh
===================================================================
RCS file: /sources/gnulib/gnulib/MODULES.html.sh,v
retrieving revision 1.212
diff -u -p -r1.212 MODULES.html.sh
--- MODULES.html.sh 1 May 2007 14:03:44 -0000 1.212
+++ MODULES.html.sh 24 May 2007 16:21:36 -0000
@@ -2029,13 +2029,14 @@ func_all_modules ()
func_module gettimeofday
func_module inet_ntop
func_module inet_pton
+ func_module lseek
+ func_module lstat
func_module mkdir
func_module mkdtemp
func_module mkstemp
func_module poll
- func_module readlink
- func_module lstat
func_module printf-posix
+ func_module readlink
func_module snprintf-posix
func_module sprintf-posix
func_module string
Index: lib/fseeko.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/fseeko.c,v
retrieving revision 1.4
diff -u -p -r1.4 fseeko.c
--- lib/fseeko.c 24 May 2007 03:53:38 -0000 1.4
+++ lib/fseeko.c 24 May 2007 16:21:36 -0000
@@ -25,12 +25,19 @@
#undef fseeko
#if !HAVE_FSEEKO
+# undef fseek
# define fseeko fseek
#endif
int
rpl_fseeko (FILE *fp, off_t offset, int whence)
{
+#if LSEEK_PIPE_BROKEN
+ /* mingw gives bogus answers rather than failure on non-seekable files. */
+ if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
+ return EOF;
+#endif
+
/* These tests are based on fpurge.c. */
#if defined _IO_ferror_unlocked /* GNU libc, BeOS */
if (fp->_IO_read_end == fp->_IO_read_ptr
Index: lib/ftello.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/ftello.c,v
retrieving revision 1.1
diff -u -p -r1.1 ftello.c
--- lib/ftello.c 24 May 2007 03:53:38 -0000 1.1
+++ lib/ftello.c 24 May 2007 16:21:36 -0000
@@ -20,14 +20,24 @@
/* Specification. */
#include <stdio.h>
+/* Get lseek. */
+#include <unistd.h>
+
#undef ftello
#if !HAVE_FTELLO
+# undef ftell
# define ftello ftell
#endif
off_t
rpl_ftello (FILE *fp)
{
+#if LSEEK_PIPE_BROKEN
+ /* mingw gives bogus answers rather than failure on non-seekable files. */
+ if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
+ return -1;
+#endif
+
#if defined __SL64 && defined __SCLE /* Cygwin */
if ((fp->_flags & __SL64) == 0)
{
Index: lib/lseek.c
===================================================================
RCS file: lib/lseek.c
diff -N lib/lseek.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/lseek.c 24 May 2007 16:21:36 -0000
@@ -0,0 +1,40 @@
+/* An lseek() function that detects pipes.
+ 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 <unistd.h>
+
+/* Get GetFileType. The replacement lseek is only used on mingw, so
+ this include can be unconditional. */
+#include <windows.h>
+#include <errno.h>
+
+#undef lseek
+
+off_t
+rpl_lseek (int fd, off_t offset, int whence)
+{
+ /* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */
+ if (GetFileType ((HANDLE) _get_osfhandle (fd)) != FILE_TYPE_DISK)
+ {
+ errno = ESPIPE;
+ return -1;
+ }
+ return lseek (fd, offset, whence);
+}
Index: lib/stdio_.h
===================================================================
RCS file: /sources/gnulib/gnulib/lib/stdio_.h,v
retrieving revision 1.26
diff -u -p -r1.26 stdio_.h
--- lib/stdio_.h 24 May 2007 03:53:38 -0000 1.26
+++ lib/stdio_.h 24 May 2007 16:21:36 -0000
@@ -42,9 +42,7 @@
#include <stdarg.h>
#include <stddef.h>
-#if (@GNULIB_FFLUSH@ && @REPLACE_FFLUSH@) \
- || (@GNULIB_FSEEKO@ && (address@hidden@ || @REPLACE_FSEEKO@)) \
- || (@GNULIB_FTELLO@ && (address@hidden@ || @REPLACE_FTELLO@))
+#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) || (@GNULIB_FTELLO@ &&
@REPLACE_FTELLO@)
/* Get off_t. */
# include <sys/types.h>
#endif
@@ -218,16 +216,13 @@ extern int vsprintf (char *str, const ch
# endif
#endif
-#if (@GNULIB_FFLUSH@ && @REPLACE_FFLUSH@) || (@GNULIB_FSEEKO@ &&
@REPLACE_FSEEKO@)
-/* Provide fseek, fseeko functions that are aware of a preceding fflush(). */
-# define fseeko rpl_fseeko
+#if @GNULIB_FSEEKO@
+# if @REPLACE_FSEEKO@
+/* Provide fseek, fseeko functions that are aware of a preceding
+ fflush(), and which detect pipes. */
+# define fseeko rpl_fseeko
extern int fseeko (FILE *fp, off_t offset, int whence);
-# define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
-#elif @GNULIB_FSEEKO@
-# if address@hidden@
-/* Assume 'off_t' is the same type as 'long'. */
-typedef int verify_fseeko_types[2 * (sizeof (off_t) == sizeof (long)) - 1];
-# define fseeko fseek
+# define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
# endif
#elif defined GNULIB_POSIXCHECK
# undef fseeko
@@ -248,13 +243,10 @@ typedef int verify_fseeko_types[2 * (siz
#endif
#if @GNULIB_FTELLO@
-# if address@hidden@
-/* Assume 'off_t' is the same type as 'long'. */
-typedef int verify_ftello_types[2 * (sizeof (off_t) == sizeof (long)) - 1];
-# define ftello ftell
-# elif @REPLACE_FTELLO@
+# if @REPLACE_FTELLO@
# define ftello rpl_ftello
extern off_t ftello (FILE *fp);
+# define ftell(fp) ftello (fp)
# endif
#elif defined GNULIB_POSIXCHECK
# undef ftello
Index: lib/unistd_.h
===================================================================
RCS file: /sources/gnulib/gnulib/lib/unistd_.h,v
retrieving revision 1.8
diff -u -p -r1.8 unistd_.h
--- lib/unistd_.h 17 May 2007 15:56:06 -0000 1.8
+++ lib/unistd_.h 24 May 2007 16:21:36 -0000
@@ -176,6 +176,25 @@ extern int getlogin_r (char *name, size_
#endif
+#if @GNULIB_LSEEK@
+# if @REPLACE_LSEEK@
+/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
+ Return the new offset if successful, otherwise -1 and errno set.
+ See the POSIX:2001 specification
+ <http://www.opengroup.org/susv3xsh/lseek.html>. */
+# define lseek rpl_lseek
+ extern off_t lseek (int fd, off_t offset, int whence);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lseek
+# define lseek(f,o,w) \
+ (GL_LINK_WARNING ("lseek does not fail with ESPIPE on non-seekable " \
+ "files on some systems - " \
+ "use gnulib module lseek for portability"), \
+ lseek (f, o, w))
+#endif
+
+
#if @GNULIB_READLINK@
/* Read the contents of the symbolic link FILE and place the first BUFSIZE
bytes of it into BUF. Return the number of bytes placed into BUF if
Index: doc/functions/fseek.texi
===================================================================
RCS file: /sources/gnulib/gnulib/doc/functions/fseek.texi,v
retrieving revision 1.1
diff -u -p -r1.1 fseek.texi
--- 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:
@@ -15,4 +17,7 @@ Portability problems not fixed by Gnulib
@item
On Windows platforms (excluding Cygwin), this function does not set @code
{errno}
upon failure.
address@hidden
+On platforms where @code{off_t} is a 32-bit type, @code{fseek} does not work
+correctly with files larger than 2 GB. The fix is to use fseeko instead.
@end itemize
Index: doc/functions/ftell.texi
===================================================================
RCS file: /sources/gnulib/gnulib/doc/functions/ftell.texi,v
retrieving revision 1.1
diff -u -p -r1.1 ftell.texi
--- 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
address@hidden
+This function mistakenly succeeds on non-seekable files: mingw.
@end itemize
Portability problems not fixed by Gnulib:
@@ -16,4 +18,7 @@ Portability problems not fixed by Gnulib
@code{fflush}, @code{ftell}, @code{ftello}, @code{fgetpos} behave incorrectly
on input streams that are opened in @code{O_TEXT} mode and whose contents
contains Unix line terminators (LF), on some platforms: mingw.
address@hidden
+On platforms where @code{off_t} is a 32-bit type, @code{ftell} does not work
+correctly with files larger than 2 GB. The fix is to use ftello instead.
@end itemize
Index: doc/functions/lseek.texi
===================================================================
RCS file: /sources/gnulib/gnulib/doc/functions/lseek.texi,v
retrieving revision 1.1
diff -u -p -r1.1 lseek.texi
--- doc/functions/lseek.texi 1 May 2007 15:11:38 -0000 1.1
+++ doc/functions/lseek.texi 24 May 2007 16:21:36 -0000
@@ -4,10 +4,12 @@
POSIX specification: @url{http://www.opengroup.org/susv3xsh/lseek.html}
-Gnulib module: ---
+Gnulib module: lseek
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:
Index: m4/fflush.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/fflush.m4,v
retrieving revision 1.5
diff -u -p -r1.5 fflush.m4
--- m4/fflush.m4 26 Apr 2007 09:33:12 -0000 1.5
+++ m4/fflush.m4 24 May 2007 16:21:36 -0000
@@ -20,9 +20,9 @@ AC_DEFUN([gl_FUNC_FFLUSH],
#include <stdio.h>
#include <unistd.h>
]], [[FILE *f = fopen ("conftest.txt", "r");
- char buffer[10];
+ char buffer[10];
int fd = fileno (f);
- if (!f || 0 > fd || fread (buffer, 1, 5, f) != 5)
+ if (!f || 0 > fd || fread (buffer, 1, 5, f) != 5)
return 2;
/* For deterministic results, ensure f read a bigger buffer. */
if (lseek (fd, 0, SEEK_CUR) == 5)
@@ -48,4 +48,5 @@ AC_DEFUN([gl_REPLACE_FFLUSH],
AC_LIBOBJ([fseeko])
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
REPLACE_FFLUSH=1
+ REPLACE_FSEEKO=1
])
Index: m4/fseeko.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/fseeko.m4,v
retrieving revision 1.5
diff -u -p -r1.5 fseeko.m4
--- m4/fseeko.m4 24 May 2007 09:44:51 -0000 1.5
+++ m4/fseeko.m4 24 May 2007 16:21:36 -0000
@@ -16,6 +16,7 @@ AC_DEFUN([gl_FUNC_FSEEKO],
])
if test $gl_cv_func_fseeko = no; then
HAVE_FSEEKO=0
+ gl_REPLACE_FSEEKO
elif test $gl_cv_var_stdin_large_offset = no; then
gl_REPLACE_FSEEKO
fi
Index: m4/ftello.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/ftello.m4,v
retrieving revision 1.3
diff -u -p -r1.3 ftello.m4
--- m4/ftello.m4 24 May 2007 09:44:51 -0000 1.3
+++ m4/ftello.m4 24 May 2007 16:21:36 -0000
@@ -16,6 +16,7 @@ AC_DEFUN([gl_FUNC_FTELLO],
])
if test $gl_cv_func_ftello = no; then
HAVE_FTELLO=0
+ gl_REPLACE_FTELLO
elif test $gl_cv_var_stdin_large_offset = no; then
gl_REPLACE_FTELLO
fi
Index: m4/lseek.m4
===================================================================
RCS file: m4/lseek.m4
diff -N m4/lseek.m4
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ m4/lseek.m4 24 May 2007 16:21:36 -0000
@@ -0,0 +1,29 @@
+# lseek.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_LSEEK],
+[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ AC_REQUIRE([AC_PROG_CC])
+ AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>],
+[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ Choke me.
+#endif])],
+ [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])])
+ if test $gl_cv_func_lseek_pipe = no; then
+ gl_REPLACE_LSEEK
+ fi
+])
+
+AC_DEFUN([gl_REPLACE_LSEEK],
+[
+ AC_LIBOBJ([lseek])
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ REPLACE_LSEEK=1
+ AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
+ [Define to 1 if lseek does not detect pipes.])
+])
Index: m4/unistd_h.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/unistd_h.m4,v
retrieving revision 1.6
diff -u -p -r1.6 unistd_h.m4
--- m4/unistd_h.m4 1 May 2007 22:15:02 -0000 1.6
+++ m4/unistd_h.m4 24 May 2007 16:21:37 -0000
@@ -39,6 +39,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE])
GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
+ GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK])
GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK])
GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP])
dnl Assume proper GNU behavior unless another module says otherwise.
@@ -50,4 +51,5 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR])
REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
+ REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
])
Index: modules/fflush
===================================================================
RCS file: /sources/gnulib/gnulib/modules/fflush,v
retrieving revision 1.7
diff -u -p -r1.7 fflush
--- modules/fflush 26 Apr 2007 13:20:51 -0000 1.7
+++ modules/fflush 24 May 2007 16:21:37 -0000
@@ -3,16 +3,16 @@ Discard pending data on both input and o
Files:
lib/fflush.c
-lib/fseeko.c
m4/fflush.m4
-m4/fseeko.m4
Depends-on:
fpurge
ftello
freading
+lseek
stdio
unistd
+fseeko
configure.ac-early:
AC_REQUIRE([AC_FUNC_FSEEKO])
Index: modules/fseeko
===================================================================
RCS file: /sources/gnulib/gnulib/modules/fseeko,v
retrieving revision 1.3
diff -u -p -r1.3 fseeko
--- modules/fseeko 24 May 2007 03:53:38 -0000 1.3
+++ modules/fseeko 24 May 2007 16:21:37 -0000
@@ -6,6 +6,7 @@ lib/fseeko.c
m4/fseeko.m4
Depends-on:
+lseek
stdio
configure.ac-early:
Index: modules/ftello
===================================================================
RCS file: /sources/gnulib/gnulib/modules/ftello,v
retrieving revision 1.3
diff -u -p -r1.3 ftello
--- modules/ftello 24 May 2007 03:53:39 -0000 1.3
+++ modules/ftello 24 May 2007 16:21:37 -0000
@@ -6,6 +6,7 @@ lib/ftello.c
m4/ftello.m4
Depends-on:
+lseek
stdio
configure.ac-early:
Index: modules/lseek
===================================================================
RCS file: modules/lseek
diff -N modules/lseek
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/lseek 24 May 2007 16:21:37 -0000
@@ -0,0 +1,24 @@
+Description:
+lseek() function: Reposition a file descriptor.
+
+Files:
+lib/lseek.c
+m4/lseek.m4
+
+Depends-on:
+unistd
+
+configure.ac:
+gl_FUNC_LSEEK
+gl_UNISTD_MODULE_INDICATOR([lseek])
+
+Makefile.am:
+
+Include:
+<unistd.h>
+
+License:
+LGPL
+
+Maintainer:
+Eric Blake
Index: modules/lseek-tests
===================================================================
RCS file: modules/lseek-tests
diff -N modules/lseek-tests
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/lseek-tests 24 May 2007 16:21:37 -0000
@@ -0,0 +1,13 @@
+Files:
+tests/test-lseek.c
+tests/test-lseek.sh
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-lseek.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
+check_PROGRAMS += test-lseek
+EXTRA_DIST += test-lseek.sh
Index: modules/stdio
===================================================================
RCS file: /sources/gnulib/gnulib/modules/stdio,v
retrieving revision 1.15
diff -u -p -r1.15 stdio
--- modules/stdio 24 May 2007 03:53:39 -0000 1.15
+++ modules/stdio 24 May 2007 16:21:37 -0000
@@ -46,9 +46,7 @@ stdio.h: stdio_.h
-e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
-e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
-e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
- -e 's|@''HAVE_FSEEKO''@|$(HAVE_FSEEKO)|g' \
-e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \
- -e 's|@''HAVE_FTELLO''@|$(HAVE_FTELLO)|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)' \
Index: modules/unistd
===================================================================
RCS file: /sources/gnulib/gnulib/modules/unistd,v
retrieving revision 1.9
diff -u -p -r1.9 unistd
--- modules/unistd 17 May 2007 15:56:07 -0000 1.9
+++ modules/unistd 24 May 2007 16:21:37 -0000
@@ -29,6 +29,7 @@ unistd.h: unistd_.h
-e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
-e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
-e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
+ -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
-e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
-e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
-e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
@@ -39,6 +40,7 @@ unistd.h: unistd_.h
-e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
-e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
-e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
+ -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
< $(srcdir)/unistd_.h; \
} > address@hidden
mv address@hidden $@
Index: tests/test-fseeko.c
===================================================================
RCS file: /sources/gnulib/gnulib/tests/test-fseeko.c,v
retrieving revision 1.2
diff -u -p -r1.2 test-fseeko.c
--- tests/test-fseeko.c 24 May 2007 03:53:39 -0000 1.2
+++ tests/test-fseeko.c 24 May 2007 16:21:37 -0000
@@ -25,8 +25,12 @@
#include <sys/types.h>
int
-main ()
+main (int argc, char **argv)
{
- /* This test assumes stdin is seekable. */
- return fseeko (stdin, (off_t)0, SEEK_CUR) != 0;
+ /* Assume stdin is seekable iff argc > 1. */
+ int expected = argc > 1 ? 0 : -1;
+ /* Exit with success only if fseek/fseeko agree. */
+ int r1 = fseeko (stdin, (off_t)0, SEEK_CUR);
+ int r2 = fseek (stdin, (long)0, SEEK_CUR);
+ return ! (r1 == r2 && r1 == expected);
}
Index: tests/test-fseeko.sh
===================================================================
RCS file: /sources/gnulib/gnulib/tests/test-fseeko.sh,v
retrieving revision 1.1
diff -u -p -r1.1 test-fseeko.sh
--- tests/test-fseeko.sh 24 May 2007 03:53:39 -0000 1.1
+++ tests/test-fseeko.sh 24 May 2007 16:21:37 -0000
@@ -1,3 +1,5 @@
#!/bin/sh
-./test-fseeko${EXEEXT} < "$srcdir/test-fseeko.sh"
+./test-fseeko${EXEEXT} 1 < "$srcdir/test-fseeko.sh" || exit 1
+echo hi | ./test-fseeko${EXEEXT} || exit 1
+exit 0
Index: tests/test-ftello.c
===================================================================
RCS file: /sources/gnulib/gnulib/tests/test-ftello.c,v
retrieving revision 1.2
diff -u -p -r1.2 test-ftello.c
--- tests/test-ftello.c 24 May 2007 03:53:39 -0000 1.2
+++ tests/test-ftello.c 24 May 2007 16:21:37 -0000
@@ -25,9 +25,12 @@
#include <sys/types.h>
int
-main ()
+main (int argc, char **argv)
{
- /* This test assumes stdin is seekable. */
- off_t pos = ftello (stdin);
- return pos < 0;
+ /* Assume stdin is seekable iff argc > 1. */
+ int expected = argc > 1 ? 0 : -1;
+ /* Exit with success only if ftell/ftello agree. */
+ off_t pos1 = ftello (stdin);
+ long pos2 = ftell (stdin);
+ return ! (pos1 == pos2 && pos1 == expected);
}
Index: tests/test-ftello.sh
===================================================================
RCS file: /sources/gnulib/gnulib/tests/test-ftello.sh,v
retrieving revision 1.1
diff -u -p -r1.1 test-ftello.sh
--- tests/test-ftello.sh 24 May 2007 03:53:39 -0000 1.1
+++ tests/test-ftello.sh 24 May 2007 16:21:37 -0000
@@ -1,3 +1,5 @@
#!/bin/sh
-./test-ftello${EXEEXT} < "$srcdir/test-ftello.sh"
+./test-ftello${EXEEXT} 1 < "$srcdir/test-ftello.sh" || exit 1
+echo hi | ./test-ftello${EXEEXT} || exit 1
+exit 0
Index: tests/test-lseek.c
===================================================================
RCS file: tests/test-lseek.c
diff -N tests/test-lseek.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-lseek.c 24 May 2007 16:21:37 -0000
@@ -0,0 +1,29 @@
+/* Test of lseek() function.
+ 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. */
+
+/* Written by Eric Blake, 2007. */
+
+#include <config.h>
+
+#include <unistd.h>
+
+int
+main ()
+{
+ /* Exit with success only if stdin is seekable. */
+ return lseek (0, (off_t)0, SEEK_CUR) < 0;
+}
Index: tests/test-lseek.sh
===================================================================
RCS file: tests/test-lseek.sh
diff -N tests/test-lseek.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-lseek.sh 24 May 2007 16:21:37 -0000
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# Succeed on seekable stdin
+./test-lseek${EXEEXT} < "$srcdir/test-lseek.sh" || exit 1
+# Fail on pipe stdin
+echo hi | ./test-lseek${EXEEXT} && exit 1
+exit 0
- mingw lseek bug, Eric Blake, 2007/05/24
- Re: mingw lseek bug, Brian Dessent, 2007/05/24
- Re: mingw lseek bug, Bruno Haible, 2007/05/24
- Re: mingw lseek bug, Eric Blake, 2007/05/24
- Re: mingw lseek bug,
Eric Blake <=
- Re: mingw lseek bug, Bruno Haible, 2007/05/24
- Re: mingw lseek bug, Eric Blake, 2007/05/24
- Re: mingw lseek bug, Bruno Haible, 2007/05/28
- Re: mingw lseek bug, Eric Blake, 2007/05/28
- Re: mingw lseek bug, Bruno Haible, 2007/05/28
- Re: mingw lseek bug, Bruno Haible, 2007/05/28
- Re: mingw lseek bug, Eric Blake, 2007/05/28
- Re: mingw lseek bug, Bruno Haible, 2007/05/28
- Re: mingw lseek bug, Eric Blake, 2007/05/28
- Re: mingw lseek bug, Bruno Haible, 2007/05/28