]> Savannah Git Hosting - gnulib.git/commitdiff
readlinkat: Work around a Cygwin 3.3.6 bug.
authorBruno Haible <bruno@clisp.org>
Tue, 4 Jun 2024 01:59:37 +0000 (03:59 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 6 Jun 2024 22:56:27 +0000 (00:56 +0200)
* m4/readlinkat.m4 (gl_FUNC_READLINKAT): Set REPLACE_READLINKAT to 1 on
Cygwin.
* lib/readlinkat.c (rpl_readlinkat): On Cygwin, for /dev/* files, don't
return results that start with a backslash.
* doc/posix-functions/readlinkat.texi: Mention the Cygwin bug.

ChangeLog
doc/posix-functions/readlinkat.texi
lib/readlinkat.c
m4/readlinkat.m4

index 06c0e34ce2773b565482e7be2a056996aed0cec1..87e652d9f469fe3b43cc8e0ec3c73c922bbb44e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-06-03  Bruno Haible  <bruno@clisp.org>
+
+       readlinkat: Work around a Cygwin 3.3.6 bug.
+       * m4/readlinkat.m4 (gl_FUNC_READLINKAT): Set REPLACE_READLINKAT to 1 on
+       Cygwin.
+       * lib/readlinkat.c (rpl_readlinkat): On Cygwin, for /dev/* files, don't
+       return results that start with a backslash.
+       * doc/posix-functions/readlinkat.texi: Mention the Cygwin bug.
+
 2024-06-03  Bruno Haible  <bruno@clisp.org>
 
        readlink: Work around a Cygwin 3.3.6 bug.
index 96ae7ec67a1c6ffdd12728a3cb9608cca96593af..9e682a43eee6b1b0ef459d436d55e3c5b2bfd1d0 100644 (file)
@@ -19,6 +19,10 @@ OS X 10.10.
 On some platforms, this function returns @code{int} instead of
 @code{ssize_t}:
 AIX 7.1.
+@item
+For the file name @file{/dev/null}, this function returns @file{\Device\Null},
+which is unusable, on some platforms:
+Cygwin 3.3.6.
 @end itemize
 
 Portability problems mostly fixed by Gnulib:
index faf85401ae6edbe86b23cdb7bb5667fe7516862f..f4d64c0d135299127bc4329071193eea867cccf3 100644 (file)
@@ -79,6 +79,16 @@ rpl_readlinkat (int fd, char const *file, char *buf, size_t bufsize)
     }
 # endif
 
+# if defined __CYGWIN__
+  /* On Cygwin 3.3.6, readlinkat(AT_FDCWD,"/dev/null") returns "\\Device\\Null",
+     which is unusable.  Better fail with EINVAL.  */
+  if (r > 0 && strncmp (file, "/dev/", 5) == 0 && buf[0] == '\\')
+    {
+      errno = EINVAL;
+      return -1;
+    }
+# endif
+
   return r;
 }
 
index 99822102294365dad985e2f030a363ccd07ed872..ba439f560cba3147eab397196a8e2454402d1ebb 100644 (file)
@@ -1,4 +1,4 @@
-# serial 8
+# serial 9
 # See if we need to provide readlinkat replacement.
 
 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
@@ -26,9 +26,12 @@ AC_DEFUN([gl_FUNC_READLINKAT],
          [AC_LANG_PROGRAM(
            [[#include <unistd.h>
              /* Check whether original declaration has correct type.  */
-             ssize_t readlinkat (int, char const *, char *, size_t);]])],
+             ssize_t readlinkat (int, char const *, char *, size_t);
+           ]])
+         ],
          [gl_cv_decl_readlinkat_works=yes],
-         [gl_cv_decl_readlinkat_works=no])])
+         [gl_cv_decl_readlinkat_works=no])
+      ])
     # Assume readlinkat has the same bugs as readlink,
     # as is the case on OS X 10.10 with trailing slashes.
     case $gl_cv_decl_readlinkat_works,$gl_cv_func_readlink_trailing_slash,$gl_cv_func_readlink_truncate in
@@ -38,5 +41,13 @@ AC_DEFUN([gl_FUNC_READLINKAT],
         REPLACE_READLINKAT=1
         ;;
     esac
+
+    dnl On Cygwin 3.3.6, readlinkat(AT_FDCWD,"/dev/null") returns
+    dnl "\\Device\\Null", which is unusable.
+    case "$host_os" in
+      cygwin*)
+        REPLACE_READLINKAT=1
+        ;;
+    esac
   fi
 ])