]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/os-windows.hpp
alien.syntax: clarify that we can dispatch off ENUM: members
[factor.git] / vm / os-windows.hpp
index a347608bb74a8c4442c5f63fa8dfb12891dcea3c..a21a67361b692a3f7ec9c9e10490cc230303912b 100644 (file)
@@ -1,14 +1,14 @@
 #include <ctype.h>
 
 #ifndef wcslen
-/* for cygwin */
+// for cygwin
 #include <wchar.h>
 #endif
 
 #if _WIN32_WINNT != 0x0600
 #undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501  /* For AddVectoredExceptionHandler, WinXP support */
-/*#define _WIN32_WINNT 0x0600  /* For CancelSynchronousIo */
+#define _WIN32_WINNT 0x0501  // For AddVectoredExceptionHandler, WinXP support
+//#define _WIN32_WINNT 0x0600  // For CancelSynchronousIo
 #endif
 
 #ifndef UNICODE
@@ -23,7 +23,7 @@
 #undef max
 #endif
 
-/* Difference between Jan 1 00:00:00 1601 and Jan 1 00:00:00 1970 */
+// Difference between Jan 1 00:00:00 1601 and Jan 1 00:00:00 1970
 #define EPOCH_OFFSET 0x019db1ded53e8000LL
 
 namespace factor {
@@ -51,8 +51,9 @@ typedef HANDLE THREADHANDLE;
 
 #define FACTOR_OS_STRING "windows"
 
-/* SSE traps raise these exception codes, which are defined in internal NT
-headers, but not winbase.h */
+// SSE traps raise these exception codes, which are defined in internal NT
+// headers
+// but not winbase.h
 #ifndef STATUS_FLOAT_MULTIPLE_FAULTS
 #define STATUS_FLOAT_MULTIPLE_FAULTS 0xC00002B4
 #endif
@@ -91,4 +92,36 @@ inline static void breakpoint() { DebugBreak(); }
 
 extern HANDLE boot_thread;
 
+inline static std::string to_utf8(const wchar_t* buffer, int len) {
+  int nChars = ::WideCharToMultiByte(
+    CP_UTF8,
+    0,
+    buffer,
+    len,
+    NULL,
+    0,
+    NULL,
+    NULL);
+  if (nChars == 0) return "";
+
+  std::string newbuffer;
+  newbuffer.resize(nChars) ;
+  ::WideCharToMultiByte(
+    CP_UTF8,
+    0,
+    buffer,
+    len,
+    const_cast<char*>(newbuffer.c_str()),
+    nChars,
+    NULL,
+    NULL);
+  return newbuffer;
+}
+
+inline static std::string to_utf8(const std::wstring& str) {
+  return to_utf8(str.c_str(), (int)str.size());
+}
+
+#define AS_UTF8(ptr) to_utf8(ptr)
+
 }