]> 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 23:25:53 +0000 (01:25 +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 4e4f01eb035b49593f276351e2518e19f0653ac6..9722b0bfd4ebf3627f63c94c3fc85fd6822715d5 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 7738ba8bfd50c09563c77c55682f96273e44e48b..f4d64c0d135299127bc4329071193eea867cccf3 100644 (file)
@@ -1,5 +1,5 @@
 /* Read a symlink relative to an open directory.
-   Copyright (C) 2009-2023 Free Software Foundation, Inc.
+   Copyright (C) 2009-2024 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
@@ -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 5c513562919ee2ad02d87a35b89227ab153143de..ba439f560cba3147eab397196a8e2454402d1ebb 100644 (file)
@@ -1,7 +1,7 @@
-# serial 8
+# serial 9
 # See if we need to provide readlinkat replacement.
 
-dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
+dnl Copyright (C) 2009-2024 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.
@@ -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
 ])