From e37cf91f24fc409fa0aa84500245f57c685fc8ea Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 30 Jul 2016 16:36:53 +0200 Subject: Implement support for Windows path actualization --- butl/path.cxx | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'butl/path.cxx') diff --git a/butl/path.cxx b/butl/path.cxx index 9325c1e..d7a0da9 100644 --- a/butl/path.cxx +++ b/butl/path.cxx @@ -7,8 +7,9 @@ #ifdef _WIN32 # include -# include // _MAX_PATH, _wgetenv() -# include // _[w]getcwd(), _[w]chdir() +# include // _find*() +# include // _MAX_PATH, _wgetenv() +# include // _[w]getcwd(), _[w]chdir() # include // SHGetFolderPath*(), CSIDL_PROFILE # include // SUCCEEDED() #else @@ -26,6 +27,7 @@ #include #include +#include // strcpy() #include #include @@ -341,4 +343,44 @@ namespace butl assert (false); // Implement if/when needed. } #endif + +#ifdef _WIN32 + template <> + LIBBUTL_EXPORT bool + basic_path_append_actual_name (string& r, + const string& d, + const string& n) + { + assert (d.size () + n.size () + 1 < _MAX_PATH); + + char p[_MAX_PATH]; + strcpy (p, d.c_str ()); + p[d.size ()] = '\\'; + strcpy (p + d.size () + 1, n.c_str ()); + + // It could be that using FindFirstFile() is faster. + // + _finddata_t fi; + intptr_t h (_findfirst (p, &fi)); + + if (h == -1 && errno == ENOENT) + return false; + + if (h == -1 || _findclose (h) == -1) + throw system_error (errno, system_category ()); + + r += fi.name; + return true; + } + + template <> + LIBBUTL_EXPORT bool + basic_path_append_actual_name (wstring&, + const wstring&, + const wstring&) + { + assert (false); // Implement if/when needed. + return false; + } +#endif } -- cgit v1.1