Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
#define WIN32_LEAN_AND_MEAN 1 | #define WIN32_LEAN_AND_MEAN 1 | ||||
#ifndef NOMINMAX | #ifndef NOMINMAX | ||||
#define NOMINMAX | #define NOMINMAX | ||||
#endif | #endif | ||||
#include <codecvt> | #include <codecvt> | ||||
#include <io.h> /* for _commit */ | #include <io.h> /* for _commit */ | ||||
#include <shellapi.h> | |||||
#include <shlobj.h> | #include <shlobj.h> | ||||
#endif | #endif | ||||
#ifdef HAVE_SYS_PRCTL_H | #ifdef HAVE_SYS_PRCTL_H | ||||
#include <sys/prctl.h> | #include <sys/prctl.h> | ||||
#endif | #endif | ||||
#ifdef HAVE_MALLOPT_ARENA_MAX | #ifdef HAVE_MALLOPT_ARENA_MAX | ||||
▲ Show 20 Lines • Show All 1,205 Lines • ▼ Show 20 Lines | |||||
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && \ | #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && \ | ||||
!defined(__OpenBSD__) | !defined(__OpenBSD__) | ||||
try { | try { | ||||
// Raises a runtime error if current locale is invalid. | // Raises a runtime error if current locale is invalid. | ||||
std::locale(""); | std::locale(""); | ||||
} catch (const std::runtime_error &) { | } catch (const std::runtime_error &) { | ||||
setenv("LC_ALL", "C", 1); | setenv("LC_ALL", "C", 1); | ||||
} | } | ||||
#elif defined(WIN32) | |||||
// Set the default input/output charset is utf-8 | |||||
SetConsoleCP(CP_UTF8); | |||||
SetConsoleOutputCP(CP_UTF8); | |||||
#endif | #endif | ||||
// The path locale is lazy initialized and to avoid deinitialization errors | // The path locale is lazy initialized and to avoid deinitialization errors | ||||
// in multithreading environments, it is set explicitly by the main thread. | // in multithreading environments, it is set explicitly by the main thread. | ||||
// A dummy locale is used to extract the internal default locale, used by | // A dummy locale is used to extract the internal default locale, used by | ||||
// fs::path, which is then used to explicitly imbue the path. | // fs::path, which is then used to explicitly imbue the path. | ||||
std::locale loc = fs::path::imbue(std::locale::classic()); | std::locale loc = fs::path::imbue(std::locale::classic()); | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
fs::path::imbue(loc); | fs::path::imbue(loc); | ||||
Show All 40 Lines | if (int ret = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m)) { | ||||
LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno)); | LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno)); | ||||
return ret; | return ret; | ||||
} | } | ||||
return 0; | return 0; | ||||
#else | #else | ||||
return 1; | return 1; | ||||
#endif | #endif | ||||
} | } | ||||
namespace util { | |||||
#ifdef WIN32 | |||||
WinCmdLineArgs::WinCmdLineArgs() { | |||||
wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc); | |||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf8_cvt; | |||||
argv = new char *[argc]; | |||||
args.resize(argc); | |||||
for (int i = 0; i < argc; i++) { | |||||
args[i] = utf8_cvt.to_bytes(wargv[i]); | |||||
argv[i] = &*args[i].begin(); | |||||
} | |||||
LocalFree(wargv); | |||||
} | |||||
WinCmdLineArgs::~WinCmdLineArgs() { | |||||
delete[] argv; | |||||
} | |||||
std::pair<int, char **> WinCmdLineArgs::get() { | |||||
return std::make_pair(argc, argv); | |||||
} | |||||
#endif | |||||
} // namespace util |