17 #if defined(__APPLE__)
18 #include <sys/sysctl.h>
19 #elif defined(unix) || defined(__unix) || defined(__unix__)
21 #include <sys/utsname.h>
25 #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
28 #define STATUS_SUCCESS 0x00000000
40 #if defined(__APPLE__)
42 #elif defined(linux) || defined(__linux) || defined(__linux__)
44 return (stat(
"/lib64/ld-linux-x86-64.so.2", &buffer) == 0);
45 #elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
48 #elif defined(_WIN32) || defined(__CYGWIN__)
49 BOOL bWow64Process = FALSE;
50 return IsWow64Process(GetCurrentProcess(), &bWow64Process) && bWow64Process;
53 #error Unsupported platform
64 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
65 #if defined(__x86_64__) || defined(__amd64__) || defined(__aarch64__) || defined(__ia64__) || defined(__ppc64__)
70 #elif defined(_WIN32) || defined(_WIN64)
77 #error Unsupported platform
97 char16_t test = 0x0102;
98 return ((
char*)&test)[0] == 0x01;
103 char16_t test = 0x0102;
104 return ((
char*)&test)[0] == 0x02;
109 #if defined(__APPLE__)
111 size_t size =
sizeof(result);
112 if (sysctlbyname(
"kern.osrelease", result, &size,
nullptr, 0) == 0)
116 #elif defined(__CYGWIN__)
118 if (uname(&name) == 0)
120 std::string result(name.sysname);
122 result.append(name.release);
124 result.append(name.version);
129 #elif defined(linux) || defined(__linux) || defined(__linux__)
130 static std::regex pattern(
"DISTRIB_DESCRIPTION=\"(.*)\"");
133 std::ifstream stream(
"/etc/lsb-release");
134 while (getline(stream, line))
137 if (std::regex_match(line, matches, pattern))
142 #elif defined(_WIN32) || defined(_WIN64)
143 static NTSTATUS(__stdcall *RtlGetVersion)(OUT PRTL_OSVERSIONINFOEXW lpVersionInformation) = (NTSTATUS(__stdcall*)(PRTL_OSVERSIONINFOEXW))GetProcAddress(GetModuleHandle(
"ntdll.dll"),
"RtlGetVersion");
144 static void(__stdcall *GetNativeSystemInfo)(OUT LPSYSTEM_INFO lpSystemInfo) = (
void(__stdcall*)(LPSYSTEM_INFO))GetProcAddress(GetModuleHandle(
"kernel32.dll"),
"GetNativeSystemInfo");
145 static BOOL(__stdcall *GetProductInfo)(IN DWORD dwOSMajorVersion, IN DWORD dwOSMinorVersion, IN DWORD dwSpMajorVersion, IN DWORD dwSpMinorVersion, OUT PDWORD pdwReturnedProductType) = (BOOL(__stdcall*)(DWORD, DWORD, DWORD, DWORD, PDWORD))GetProcAddress(GetModuleHandle(
"kernel32.dll"),
"GetProductInfo");
147 OSVERSIONINFOEXW osvi;
148 ZeroMemory(&osvi,
sizeof(OSVERSIONINFOEXW));
149 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEXW);
151 if (RtlGetVersion !=
nullptr)
153 NTSTATUS ntRtlGetVersionStatus = RtlGetVersion(&osvi);
154 if (ntRtlGetVersionStatus != STATUS_SUCCESS)
159 #if defined(_MSC_VER)
160 #pragma warning(push)
161 #pragma warning(disable: 4996)
163 BOOL bOsVersionInfoEx = GetVersionExW((OSVERSIONINFOW*)&osvi);
164 if (bOsVersionInfoEx == 0)
166 #if defined(_MSC_VER)
172 ZeroMemory(&si,
sizeof(SYSTEM_INFO));
174 if (GetNativeSystemInfo !=
nullptr)
175 GetNativeSystemInfo(&si);
179 if ((osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) || (osvi.dwMajorVersion <= 4))
184 std::stringstream os;
188 if (osvi.dwMajorVersion >= 6)
190 if (osvi.dwMajorVersion == 10)
192 if (osvi.dwMinorVersion == 0)
194 if (osvi.wProductType == VER_NT_WORKSTATION)
196 if (osvi.dwBuildNumber >= 22000)
203 if (osvi.dwBuildNumber >= 20348)
204 os <<
"Windows Server 2022 ";
205 else if (osvi.dwBuildNumber >= 17763)
206 os <<
"Windows Server 2019 ";
208 os <<
"Windows Server 2016 ";
212 else if (osvi.dwMajorVersion == 6)
214 if (osvi.dwMinorVersion == 3)
216 if (osvi.wProductType == VER_NT_WORKSTATION)
217 os <<
"Windows 8.1 ";
219 os <<
"Windows Server 2012 R2 ";
221 else if (osvi.dwMinorVersion == 2)
223 if (osvi.wProductType == VER_NT_WORKSTATION)
226 os <<
"Windows Server 2012 ";
228 else if (osvi.dwMinorVersion == 1)
230 if (osvi.wProductType == VER_NT_WORKSTATION)
233 os <<
"Windows Server 2008 R2 ";
235 else if (osvi.dwMinorVersion == 0)
237 if (osvi.wProductType == VER_NT_WORKSTATION)
238 os <<
"Windows Vista ";
240 os <<
"Windows Server 2008 ";
245 if ((GetProductInfo !=
nullptr) && GetProductInfo(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType))
249 case PRODUCT_ULTIMATE:
250 os <<
"Ultimate Edition";
252 case PRODUCT_PROFESSIONAL:
253 os <<
"Professional";
255 case PRODUCT_HOME_PREMIUM:
256 os <<
"Home Premium Edition";
258 case PRODUCT_HOME_BASIC:
259 os <<
"Home Basic Edition";
261 case PRODUCT_ENTERPRISE:
262 os <<
"Enterprise Edition";
264 case PRODUCT_BUSINESS:
265 os <<
"Business Edition";
267 case PRODUCT_STARTER:
268 os <<
"Starter Edition";
270 case PRODUCT_CLUSTER_SERVER:
271 os <<
"Cluster Server Edition";
273 case PRODUCT_DATACENTER_SERVER:
274 os <<
"Datacenter Edition";
276 case PRODUCT_DATACENTER_SERVER_CORE:
277 os <<
"Datacenter Edition (core installation)";
279 case PRODUCT_ENTERPRISE_SERVER:
280 os <<
"Enterprise Edition";
282 case PRODUCT_ENTERPRISE_SERVER_CORE:
283 os <<
"Enterprise Edition (core installation)";
285 case PRODUCT_ENTERPRISE_SERVER_IA64:
286 os <<
"Enterprise Edition for Itanium-based Systems";
288 case PRODUCT_SMALLBUSINESS_SERVER:
289 os <<
"Small Business Server";
291 case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
292 os <<
"Small Business Server Premium Edition";
294 case PRODUCT_STANDARD_SERVER:
295 os <<
"Standard Edition";
297 case PRODUCT_STANDARD_SERVER_CORE:
298 os <<
"Standard Edition (core installation)";
300 case PRODUCT_WEB_SERVER:
301 os <<
"Web Server Edition";
306 else if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 2))
308 if (GetSystemMetrics(SM_SERVERR2))
309 os <<
"Windows Server 2003 R2, ";
310 else if (osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER)
311 os <<
"Windows Storage Server 2003";
312 else if (osvi.wSuiteMask & VER_SUITE_WH_SERVER)
313 os <<
"Windows Home Server";
314 else if ((osvi.wProductType == VER_NT_WORKSTATION) && (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64))
315 os <<
"Windows XP Professional x64 Edition";
317 os <<
"Windows Server 2003, ";
318 if (osvi.wProductType != VER_NT_WORKSTATION)
320 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
322 if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
323 os <<
"Datacenter Edition for Itanium-based Systems";
324 else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
325 os <<
"Enterprise Edition for Itanium-based Systems";
327 else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
329 if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
330 os <<
"Datacenter x64 Edition";
331 else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
332 os <<
"Enterprise x64 Edition";
334 os <<
"Standard x64 Edition";
338 if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
339 os <<
"Compute Cluster Edition";
340 else if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
341 os <<
"Datacenter Edition";
342 else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
343 os <<
"Enterprise Edition";
344 else if (osvi.wSuiteMask & VER_SUITE_BLADE)
347 os <<
"Standard Edition";
351 else if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 1))
354 if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
355 os <<
"Home Edition";
357 os <<
"Professional";
359 else if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 0))
361 os <<
"Windows 2000 ";
362 if (osvi.wProductType == VER_NT_WORKSTATION)
363 os <<
"Professional";
366 if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
367 os <<
"Datacenter Server";
368 else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
369 os <<
"Advanced Server";
376 std::wstring sp_version(osvi.szCSDVersion);
377 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;
378 if (std::wcslen(osvi.szCSDVersion) > 0)
379 os <<
" " << convert.to_bytes(sp_version.data(), sp_version.data() + sp_version.size());
382 os <<
" (build " << osvi.dwBuildNumber <<
")";
385 if (osvi.dwMajorVersion >= 6)
387 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
389 else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
391 else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
392 os <<
", Intel Itanium";
393 else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM)
395 #if !defined(__MINGW32__) && !defined(__MINGW64__)
396 else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM64)
403 #error Unsupported platform
409 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
411 #elif defined(_WIN32) || defined(_WIN64)
414 #error Unsupported platform
430 return std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
static bool IsDebug()
Is compiled in debug mode?
static std::string OSVersion()
Get OS version string.
static bool IsRelease()
Is compiled in release mode?
static time_t Timestamp()
Get the current time in seconds.
static bool Is64BitProcess()
Is 64-bit running process?
static bool IsLittleEndian()
Is little-endian system?
static std::string WindowsEndLine()
Get Windows text end line separator.
static std::string EndLine()
Get text end line separator.
static std::string UnixEndLine()
Get Unix text end line separator.
static bool Is64BitOS()
Is 64-bit OS?
static bool Is32BitOS()
Is 32-bit OS?
static bool Is32BitProcess()
Is 32-bit running process?
static bool IsBigEndian()
Is big-endian system?
Environment management definition.
C++ Benchmark project definitions.