| 62 | #endif |
| 63 | |
| 64 | void SetupEnvironment() |
| 65 | { |
| 66 | #ifdef HAVE_MALLOPT_ARENA_MAX |
| 67 | // glibc-specific: On 32-bit systems set the number of arenas to 1. |
| 68 | // By default, since glibc 2.10, the C library will create up to two heap |
| 69 | // arenas per core. This is known to cause excessive virtual address space |
| 70 | // usage in our usage. Work around it by setting the maximum number of |
| 71 | // arenas to 1. |
| 72 | if (sizeof(void*) == 4) { |
| 73 | mallopt(M_ARENA_MAX, 1); |
| 74 | } |
| 75 | #endif |
| 76 | // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale |
| 77 | // may be invalid, in which case the "C.UTF-8" locale is used as fallback. |
| 78 | #if !defined(WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) |
| 79 | try { |
| 80 | std::locale(""); // Raises a runtime error if current locale is invalid |
| 81 | } catch (const std::runtime_error&) { |
| 82 | setenv("LC_ALL", "C.UTF-8", 1); |
| 83 | } |
| 84 | #elif defined(WIN32) |
| 85 | assert(GetACP() == CP_UTF8); |
| 86 | // Set the default input/output charset is utf-8 |
| 87 | SetConsoleCP(CP_UTF8); |
| 88 | SetConsoleOutputCP(CP_UTF8); |
| 89 | #endif |
| 90 | |
| 91 | #ifndef WIN32 |
| 92 | constexpr mode_t private_umask = 0077; |
| 93 | umask(private_umask); |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | bool SetupNetworking() |
| 98 | { |
no outgoing calls