]> Savannah Git Hosting - gnulib.git/commitdiff
getcwd: Return "/bin" instead of "//bin" on Adélie Linux.
authorBruno Haible <bruno@clisp.org>
Tue, 31 Dec 2024 18:38:42 +0000 (19:38 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 31 Dec 2024 18:41:28 +0000 (19:41 +0100)
Reported by Zach van Rijn <me@zv.io> in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-04/msg00072.html>
and <https://git.adelielinux.org/adelie/packages/-/issues/987>.

* lib/getcwd.c (__getcwd_generic): Remove a trailing slash from the
result of readlink().

ChangeLog
lib/getcwd.c

index 50b46a32d07ff18e5e21f043522d141c7ed17cf3..4b7c72c9063bc2e9bef0f73c3bc83c24d60cfeff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-12-31  Bruno Haible  <bruno@clisp.org>
+
+       getcwd: Return "/bin" instead of "//bin" on Adélie Linux.
+       Reported by Zach van Rijn <me@zv.io> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2023-04/msg00072.html>
+       and <https://git.adelielinux.org/adelie/packages/-/issues/987>.
+       * lib/getcwd.c (__getcwd_generic): Remove a trailing slash from the
+       result of readlink().
+
 2024-12-28  Bruno Haible  <bruno@clisp.org>
 
        endian: Fix link error on CentOS 5.
index 214950a144732bfee21ffe39c72bd9686947f416..d637b4e576629c4d7d5112d96436df172d582f17 100644 (file)
@@ -478,6 +478,12 @@ __getcwd_generic (char *buf, size_t size)
             }
           else
             {
+              /* *dirp is already a '/' (see above).  Therefore if the directory
+                 ends in a slash, we can remove that slash.  This happens in
+                 particular if the directory is "/".  */
+              if (linklen > 0 && linkbuf[linklen - 1] == '/')
+                linklen--;
+
               dirroom = dirp - dir;
               if (dirroom < linklen)
                 {