From 70db0db7bf9fe648584f4e00a71c8c3b272a5d03 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 10 Mar 2014 19:26:45 +0200 Subject: [PATCH] Fix an obscure bug in fstatat on Windows 9X. src/w32.c (fstatat): Don't add an extra slash if the argument ends with a slash: this fails the subsequent call to stat_worker on Windows 9X. Reported by oslsachem . --- src/ChangeLog | 6 ++++++ src/w32.c | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index c383aeaa0a0..62ad09eb4c2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2014-03-10 Eli Zaretskii + + * w32.c (fstatat): Don't add an extra slash if the argument ends + with a slash: this fails the subsequent call to stat_worker on + Windows 9X. Reported by oslsachem . + 2014-03-10 Martin Rudalics * w32term.c (w32_read_socket): In SIZE_RESTORED case diff --git a/src/w32.c b/src/w32.c index 11fb2a72f69..e84c63d674c 100644 --- a/src/w32.c +++ b/src/w32.c @@ -5138,7 +5138,10 @@ fstatat (int fd, char const *name, struct stat *st, int flags) if (fd != AT_FDCWD) { - if (_snprintf (fullname, sizeof fullname, "%s/%s", dir_pathname, name) + char lastc = dir_pathname[strlen (dir_pathname) - 1]; + + if (_snprintf (fullname, sizeof fullname, "%s%s%s", + dir_pathname, IS_DIRECTORY_SEP (lastc) ? "" : "/", name) < 0) { errno = ENAMETOOLONG;