#include <ctype.h>
#ifndef wcslen
-/* for cygwin */
+// for cygwin
#include <wchar.h>
#endif
#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 {
#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"
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)
+
}