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/process.cxx | 49 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-) (limited to 'butl/process.cxx') diff --git a/butl/process.cxx b/butl/process.cxx index 588c0b6..aaab915 100644 --- a/butl/process.cxx +++ b/butl/process.cxx @@ -8,10 +8,8 @@ # include // execvp, fork, dup2, pipe, chdir, *_FILENO, getpid # include // waitpid #else -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -# include // CreatePipe(), CreateProcess() +# include + # include // _open_osfhandle(), _get_osfhandle(), _close() # include // _O_TEXT # include // getenv() @@ -21,6 +19,7 @@ # include // unique_ptr # include +# include #endif #include @@ -29,6 +28,10 @@ using namespace std; +#ifdef _WIN32 +using namespace butl::win32; +#endif + namespace butl { class auto_fd @@ -226,38 +229,6 @@ namespace butl #else // _WIN32 - struct msg_deleter - { - void operator() (char* p) const {LocalFree (p);} - }; - - static string - error (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; - } - - static inline string - last_error () - { - return error (GetLastError ()); - } - static path path_search (const path& f) { @@ -383,7 +354,7 @@ namespace butl auto fail = [](const char* m = nullptr) { - throw process_error (m == nullptr ? last_error () : m); + throw process_error (m == nullptr ? last_error_msg () : m); }; // Create a pipe and clear the inherit flag on the parent side. @@ -605,7 +576,7 @@ namespace butl handle = 0; // We have tried. if (e != NO_ERROR) - throw process_error (error (e)); + throw process_error (error_msg (e)); status = s; } @@ -631,7 +602,7 @@ namespace butl handle = 0; // We have tried. if (e != NO_ERROR) - throw process_error (error (e)); + throw process_error (error_msg (e)); status = s; } -- cgit v1.1