From 85e469019f8e9e02b28354df21ddaf3564e905d7 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 9 Feb 2013 10:43:11 +0100 Subject: [PATCH] Windows bugfixes for Utility::DirName and Utility::Glob. --- lib/base/utility.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 49707a7e1..f22f611ab 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -267,12 +267,27 @@ bool Utility::Match(const String& pattern, const String& text) */ String Utility::DirName(const String& path) { - char *dir = strdup(path.CStr()); - String result; + char *dir; + +#ifdef _WIN32 + String dupPath = path; + + /* PathRemoveFileSpec doesn't properly handle forward slashes. */ + BOOST_FOREACH(char& ch, dupPath) { + if (ch == '/') + ch = '\\'; + } + + dir = strdup(dupPath.CStr()); +#else /* _WIN32 */ + dir = strdup(path.CStr()); +#endif /* _WIN32 */ if (dir == NULL) BOOST_THROW_EXCEPTION(bad_alloc()); + String result; + #ifndef _WIN32 result = dirname(dir); #else /* _WIN32 */ @@ -464,7 +479,7 @@ bool Utility::Glob(const String& pathSpec, const function& } do { - callback(wfd.cFileName); + callback(DirName(pathSpec) + "/" + wfd.cFileName); } while (FindNextFile(handle, &wfd)); if (!FindClose(handle))