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=1faeb19d2ab14dbd7b8128419d0aeaa3ed9f9a84;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 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) {