aboutsummaryrefslogtreecommitdiff
path: root/libbutl/win32-utility.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-05-01 16:08:43 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-05-01 16:59:24 +0300
commit61377c582e0f2675baa5f5e6e30a35d1a4164b33 (patch)
tree11cdca992834d7f7f197f72856712fbcb3020e3d /libbutl/win32-utility.cxx
parent442c1a6790e52baa0c081f310d4d9e9b6f1ff638 (diff)
Add hxx extension for headers and lib prefix for library dir
Diffstat (limited to 'libbutl/win32-utility.cxx')
-rw-r--r--libbutl/win32-utility.cxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/libbutl/win32-utility.cxx b/libbutl/win32-utility.cxx
new file mode 100644
index 0000000..c16f8cc
--- /dev/null
+++ b/libbutl/win32-utility.cxx
@@ -0,0 +1,54 @@
+// file : libbutl/win32-utility.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <libbutl/win32-utility.hxx>
+
+// Note that while we exclude it from the buildfile-based builds, we still
+// need these guards for build2 bootstrap.
+//
+#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