From e0b126d8c7f691856ec4d80bb57cb1ba5c71fd69 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 22 Jun 2016 23:00:36 +0300 Subject: Add mkslink(), mkhlink() --- butl/path.cxx | 50 ++++++++++---------------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) (limited to 'butl/path.cxx') diff --git a/butl/path.cxx b/butl/path.cxx index 92b0d6c..1693c86 100644 --- a/butl/path.cxx +++ b/butl/path.cxx @@ -5,15 +5,12 @@ #include #ifdef _WIN32 +# include + # include // _MAX_PATH, _wgetenv() # include // _[w]getcwd(), _[w]chdir() -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -# include // GetTempPath*(), FormatMessageA(), LocalFree() # include // SHGetFolderPath*(), CSIDL_PROFILE # include // SUCCEEDED() -# include // unique_ptr #else # include // struct passwd, getpwuid_r() # include // EINVAL @@ -23,6 +20,7 @@ # include // strlen(), strcpy() # include // stat(), S_IS* # include // stat + # include #endif @@ -40,6 +38,10 @@ using namespace std; +#ifdef _WIN32 +using namespace butl::win32; +#endif + namespace butl { char const* invalid_path_base:: @@ -84,39 +86,7 @@ namespace butl #endif } -#ifdef _WIN32 - struct msg_deleter - { - void operator() (char* p) const {LocalFree (p);} - }; - - static string - error_msg (DWORD e) - { - char* msg; - if (!FormatMessageA ( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_MAX_WIDTH_MASK, - 0, - e, - MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), - (char*)&msg, - 0, - 0)) - return "unknown error code " + to_string (e); - - unique_ptr m (msg); - return msg; - } - - inline static string - last_error () - { - return error_msg (GetLastError ()); - } -#else +#ifndef _WIN32 static const char* temp_directory () { @@ -179,7 +149,7 @@ namespace butl if (r == 0) { - string e (last_error ()); + string e (last_error_msg ()); throw system_error (ENOTDIR, system_category (), e); } @@ -301,7 +271,7 @@ namespace butl if (r == 0) { - string e (last_error ()); + string e (last_error_msg ()); throw system_error (ENOTDIR, system_category (), e); } #else -- cgit v1.1