From 4f73df1c4f401a56dfcb1ad6bcc01e830b3b3d5d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 2 Aug 2009 18:58:51 +0000 Subject: Add handling of relative paths to emu.cpp's openfile(), needed to handle relative paths in test configuration on Windows. --- lib/win32/emu.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/win32/emu.cpp') diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp index ad8c3041..3a56661a 100644 --- a/lib/win32/emu.cpp +++ b/lib/win32/emu.cpp @@ -417,6 +417,32 @@ std::string ConvertPathToAbsoluteUnicode(const char *pFileName) } tmpStr += filename; + + // We are using direct filename access, which does not support .., + // so we need to implement it ourselves. + + for (std::string::size_type i = 1; i < tmpStr.size() - 3; i++) + { + if (tmpStr.substr(i, 3) == "\\..") + { + std::string::size_type lastSlash = + tmpStr.rfind('\\', i - 1); + + if (lastSlash == std::string::npos) + { + // no previous directory, ignore it, + // CreateFile will fail with error 123 + } + else + { + tmpStr.replace(lastSlash, i + 3 - lastSlash, + ""); + } + + i = lastSlash; + } + } + return tmpStr; } -- cgit v1.2.3