]> Savannah Git Hosting - gnulib.git/commitdiff
ftell, ftello: Fix recognition of pipes on native Windows.
authorBruno Haible <bruno@clisp.org>
Mon, 24 Apr 2023 17:48:47 +0000 (19:48 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 24 Apr 2023 17:48:47 +0000 (19:48 +0200)
* m4/lseek.m4 (gl_FUNC_LSEEK): Update comment.
* m4/ftello.m4 (gl_FUNC_FTELLO): On native Windows, set REPLACE_FTELLO=1
always.
* doc/posix-functions/ftello.texi: Mention the behaviour on pipes.
* doc/posix-functions/ftell.texi: Likewise.
* doc/posix-functions/fgetpos.texi: Likewise.

ChangeLog
doc/posix-functions/fgetpos.texi
doc/posix-functions/ftell.texi
doc/posix-functions/ftello.texi
m4/ftello.m4
m4/lseek.m4

index 853e9085f68f3b73fcb2c51e6f3e4d3a2f8c9f55..0420fa8c9eaaa65d3d03c04b34decb41c7813fad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-04-24  Bruno Haible  <bruno@clisp.org>
+
+       ftell, ftello: Fix recognition of pipes on native Windows.
+       * m4/lseek.m4 (gl_FUNC_LSEEK): Update comment.
+       * m4/ftello.m4 (gl_FUNC_FTELLO): On native Windows, set REPLACE_FTELLO=1
+       always.
+       * doc/posix-functions/ftello.texi: Mention the behaviour on pipes.
+       * doc/posix-functions/ftell.texi: Likewise.
+       * doc/posix-functions/fgetpos.texi: Likewise.
+
 2023-04-24  Bruno Haible  <bruno@clisp.org>
 
        lseek: Fix module dependencies (regression 2021-11-15).
index 89e3acd58fafb45434560ab51b2fb77d5fba4186..4a0051ea235554ff0fb52c51ae1cd30b77138bba 100644 (file)
@@ -19,4 +19,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, MSVC 14.
+@item
+This function mistakenly succeeds on pipes on some platforms:
+mingw 10.
 @end itemize
index 5a15dee8ea8eaef760e8426c118581f8ce8a860e..5d79f5576bf64e8103494144d845a5812e87f131 100644 (file)
@@ -20,6 +20,9 @@ This function, when invoked after @code{ungetc}, throws away the @code{ungetc}
 buffer, changes the stream's file position, and returns the wrong position on
 some platforms:
 macOS 10.15 and newer.
+@item
+This function mistakenly succeeds on pipes on some platforms:
+mingw 10.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index ded1df0c114e7422cf1aed8213671de49a74f47b..4e9427015c15261b9a7c616804d4c8c4c1c813e1 100644 (file)
@@ -27,6 +27,9 @@ macOS 10.15 and newer.
 @item
 This function fails on seekable stdin, stdout, and stderr: cygwin <= 1.5.24.
 @item
+This function mistakenly succeeds on pipes on some platforms:
+mingw 10.
+@item
 On platforms where @code{off_t} is a 32-bit type, @code{ftello} does not work
 correctly with files 2 GiB and larger.  @xref{Large File Support}.
 @end itemize
index 4901b16835b60894d1d2cab44d0ec1ad974454aa..e13fcd93d23f4e157ab3fabf05af6657993bb428 100644 (file)
@@ -1,4 +1,4 @@
-# ftello.m4 serial 14
+# ftello.m4 serial 15
 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -37,13 +37,24 @@ AC_DEFUN([gl_FUNC_FTELLO],
     if test $gl_cv_var_stdin_large_offset = no; then
       REPLACE_FTELLO=1
     fi
+    AC_REQUIRE([AC_CANONICAL_HOST])
+    if test $REPLACE_FTELLO = 0; then
+      dnl On native Windows, in some circumstances, ftell(), ftello(),
+      dnl fgetpos(), lseek(), _lseeki64() all succeed on devices of type
+      dnl FILE_TYPE_PIPE. However, to match POSIX behaviour, we want
+      dnl ftell(), ftello(), fgetpos(), lseek() to fail when the argument fd
+      dnl designates a pipe. See also
+      dnl https://github.com/python/cpython/issues/78961#issuecomment-1093800325
+      case "$host_os" in
+        mingw*) REPLACE_FTELLO=1 ;;
+      esac
+    fi
     if test $REPLACE_FTELLO = 0; then
       dnl Detect bug on Solaris.
       dnl ftell and ftello produce incorrect results after putc that followed a
       dnl getc call that reached EOF on Solaris. This is because the _IOREAD
       dnl flag does not get cleared in this case, even though _IOWRT gets set,
       dnl and ftell and ftello look whether the _IOREAD flag is set.
-      AC_REQUIRE([AC_CANONICAL_HOST])
       AC_CACHE_CHECK([whether ftello works],
         [gl_cv_func_ftello_works],
         [
index 6e1ab6ffaa0a676e73d69ca4924c6cb7cc286bdd..0da458804fb4cf618a80683c6c27bd2129beb4cc 100644 (file)
@@ -1,4 +1,4 @@
-# lseek.m4 serial 13
+# lseek.m4 serial 14
 dnl Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -17,9 +17,11 @@ AC_DEFUN([gl_FUNC_LSEEK],
          dnl Native Windows.
          dnl The result of lseek (fd, (off_t)0, SEEK_CUR) or
          dnl SetFilePointer(handle, 0, NULL, FILE_CURRENT)
-         dnl for a pipe depends on the environment: In a Cygwin 1.5
-         dnl environment it succeeds (wrong); in a Cygwin 1.7 environment
-         dnl it fails with a wrong errno value.
+         dnl for a pipe depends on the environment:
+         dnl In a Cygwin 1.5 environment it succeeds (wrong);
+         dnl in a Cygwin 1.7 environment it fails with a wrong errno value;
+         dnl in a Cygwin 2.9.0 environment it fails correctly;
+         dnl in a Cygwin 3.4.6 environment it succeeds again (wrong).
          gl_cv_func_lseek_pipe=no
          ;;
        *)