From dcccba655fe848564e961b3f285ce3a82d3ac73a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 7 Mar 2020 14:07:28 +0300 Subject: Add more support for symlinks on Windows See mksymlink() for details of the symlinks support on Windows. --- libbutl/win32-utility.cxx | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'libbutl/win32-utility.cxx') diff --git a/libbutl/win32-utility.cxx b/libbutl/win32-utility.cxx index b4dda6a..3b44d60 100644 --- a/libbutl/win32-utility.cxx +++ b/libbutl/win32-utility.cxx @@ -9,9 +9,14 @@ #ifdef _WIN32 #ifndef __cpp_lib_modules_ts +#include #include // unique_ptr + +#include // throw_system_error() #else import std.core; + +import butl.utility; #endif using namespace std; @@ -20,6 +25,25 @@ namespace butl { namespace win32 { + const nullhandle_t nullhandle (INVALID_HANDLE_VALUE); + + void auto_handle:: + close () + { + if (handle_ != INVALID_HANDLE_VALUE) + { + bool r (CloseHandle (handle_)); + + // If CloseHandle() failed then no reason to expect it to succeed the + // next time. + // + handle_ = INVALID_HANDLE_VALUE; + + if (!r) + throw_system_error (GetLastError ()); + } + } + struct msg_deleter { void operator() (char* p) const {LocalFree (p);} @@ -40,7 +64,7 @@ namespace butl (char*)&msg, 0, 0)) - return "unknown error code " + to_string (code); + return "unknown error code " + std::to_string (code); unique_ptr m (msg); return msg; -- cgit v1.1