From: Bruno Haible Date: Tue, 4 Jun 2024 01:59:37 +0000 (+0200) Subject: readlinkat: Work around a Cygwin 3.3.6 bug. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=861b8d3deb4ba850338c9d6092db9dd841947796;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 06c0e34ce2..87e652d9f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-06-03 Bruno Haible + + 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 readlink: Work around a Cygwin 3.3.6 bug. diff --git a/doc/posix-functions/readlinkat.texi b/doc/posix-functions/readlinkat.texi index 96ae7ec67a..9e682a43ee 100644 --- a/doc/posix-functions/readlinkat.texi +++ b/doc/posix-functions/readlinkat.texi @@ -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: diff --git a/lib/readlinkat.c b/lib/readlinkat.c index faf85401ae..f4d64c0d13 100644 --- a/lib/readlinkat.c +++ b/lib/readlinkat.c @@ -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; } diff --git a/m4/readlinkat.m4 b/m4/readlinkat.m4 index 9982210229..ba439f560c 100644 --- a/m4/readlinkat.m4 +++ b/m4/readlinkat.m4 @@ -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 /* 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 ])