From: Bruno Haible Date: Tue, 31 Dec 2024 18:38:42 +0000 (+0100) Subject: getcwd: Return "/bin" instead of "//bin" on Adélie Linux. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fstable-202401;p=gnulib.git getcwd: Return "/bin" instead of "//bin" on Adélie Linux. Reported by Zach van Rijn in and . * lib/getcwd.c (__getcwd_generic): Remove a trailing slash from the result of readlink(). --- diff --git a/ChangeLog b/ChangeLog index dc27be4ab8..60545bc962 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-12-31 Bruno Haible + + getcwd: Return "/bin" instead of "//bin" on Adélie Linux. + Reported by Zach van Rijn in + + and . + * lib/getcwd.c (__getcwd_generic): Remove a trailing slash from the + result of readlink(). + 2024-12-28 Bruno Haible assert-h, verify: Make static_assert work in C++ mode on FreeBSD 11. diff --git a/lib/getcwd.c b/lib/getcwd.c index 214950a144..d637b4e576 100644 --- a/lib/getcwd.c +++ b/lib/getcwd.c @@ -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) {