]> 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:38:42 +0000 (19:38 +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 8c4b4df53b771ffefdd1ad6fd126ff29ce201edb..6f24603e3ea5ad045c80502745ecce3ef2a587f8 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-30  Collin Funk  <collin.funk1@gmail.com>
 
        servent: Add tests.
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)
                 {