]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/os-windows.hpp
Put brackets around ipv6 addresses in `inet6 present`
[factor.git] / vm / os-windows.hpp
index cca3c7e77642a77204498d13d47d5533897ba479..a21a67361b692a3f7ec9c9e10490cc230303912b 100644 (file)
@@ -92,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)
+
 }