From 1faeb19d2ab14dbd7b8128419d0aeaa3ed9f9a84 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 31 Dec 2024 19:38:42 +0100 Subject: [PATCH] =?utf8?q?getcwd:=20Return=20"/bin"=20instead=20of=20"//bi?= =?utf8?q?n"=20on=20Ad=C3=A9lie=20Linux.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reported by Zach van Rijn in and . * lib/getcwd.c (__getcwd_generic): Remove a trailing slash from the result of readlink(). --- ChangeLog | 9 +++++++++ lib/getcwd.c | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 50b46a32d0..4b7c72c906 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 endian: Fix link error on CentOS 5. 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) { -- 2.39.5