aboutsummaryrefslogtreecommitdiff
path: root/butl/win32-utility.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-06-22 23:00:36 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-06-23 15:13:25 +0300
commite0b126d8c7f691856ec4d80bb57cb1ba5c71fd69 (patch)
tree20613b639d81a08dd1189ef4db37f41f3de54a68 /butl/win32-utility.cxx
parent748eab79085d7c8a3b3da90316a90a892db884ae (diff)
Add mkslink(), mkhlink()
Diffstat (limited to 'butl/win32-utility.cxx')
-rw-r--r--butl/win32-utility.cxx51
1 files changed, 51 insertions, 0 deletions
diff --git a/butl/win32-utility.cxx b/butl/win32-utility.cxx
new file mode 100644
index 0000000..cf44d4d
--- /dev/null
+++ b/butl/win32-utility.cxx
@@ -0,0 +1,51 @@
+// file : butl/win32-utility.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <butl/win32-utility>
+
+#ifdef _WIN32
+
+#include <memory> // unique_ptr
+
+using namespace std;
+
+namespace butl
+{
+ namespace win32
+ {
+ struct msg_deleter
+ {
+ void operator() (char* p) const {LocalFree (p);}
+ };
+
+ string
+ error_msg (DWORD code)
+ {
+ char* msg;
+ if (!FormatMessageA (
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ 0,
+ code,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (char*)&msg,
+ 0,
+ 0))
+ return "unknown error code " + to_string (code);
+
+ unique_ptr<char, msg_deleter> m (msg);
+ return msg;
+ }
+
+ string
+ last_error_msg ()
+ {
+ return error_msg (GetLastError ());
+ }
+ }
+}
+
+#endif // _WIN32