]> 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 1f9a1da7156166d2c603aa06e399271771a7fde4..a21a67361b692a3f7ec9c9e10490cc230303912b 100644 (file)
@@ -1,12 +1,15 @@
 #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
+#define _WIN32_WINNT 0x0501  // For AddVectoredExceptionHandler, WinXP support
+//#define _WIN32_WINNT 0x0600  // For CancelSynchronousIo
+#endif
 
 #ifndef UNICODE
 #define UNICODE
@@ -20,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 {
@@ -41,17 +44,13 @@ typedef HANDLE THREADHANDLE;
 #ifdef _MSC_VER
 #define FTELL ftell
 #define FSEEK fseek
-#define SNPRINTF _snprintf
 #else
 #define FTELL ftello64
 #define FSEEK fseeko64
-#define SNPRINTF snprintf
 #endif
 
 #define FACTOR_OS_STRING "windows"
 
-#define FACTOR_DLL NULL
-
 // SSE traps raise these exception codes, which are defined in internal NT
 // headers
 // but not winbase.h
@@ -65,12 +64,12 @@ typedef HANDLE THREADHANDLE;
 
 #define OPEN_READ(path) _wfopen((path), L"rb")
 #define OPEN_WRITE(path) _wfopen((path), L"wb")
+#define THREADSAFE_STRERROR(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
 
 inline static void early_init() {}
 uint64_t nano_count();
 void sleep_nanos(uint64_t nsec);
 long getpagesize();
-void move_file(const vm_char* path1, const vm_char* path2);
 VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
                                 void* dispatch);
 THREADHANDLE start_thread(void* (*start_routine)(void*), void* args);
@@ -90,4 +89,39 @@ inline static void breakpoint() { DebugBreak(); }
 #define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
 #define FUNCTION_CODE_POINTER(ptr) ptr
 #define FUNCTION_TOC_POINTER(ptr) ptr
+
+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)
+
 }