DSL
os_version.cpp
1 //@AUTOHEADER@BEGIN@
2 /***********************************************************************\
3 | Drift Standard Libraries v1.01 |
4 | Copyright 2010-2023 Drift Solutions / Indy Sams |
5 | Docs and more information available at https://www.driftsolutions.dev |
6 | This file released under the 3-clause BSD license, |
7 | see included DSL.LICENSE.TXT file for details. |
8 \***********************************************************************/
9 //@AUTOHEADER@END@
10 
11 #include <drift/dslcore.h>
12 #include <drift/os_version.h>
13 
14 #ifdef WIN32
15 const char * DSL_CC GetOSVersion() {
16  if (Is64Bit()) {
17  return "Windows (64-bit)";
18  } else {
19  return "Windows (32-bit)";
20  }
21 }
22 
23 typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
24 LPFN_ISWOW64PROCESS fnIsWow64Process=NULL;
25 
26 bool DSL_CC Is64Bit() {
27 #ifdef WIN64
28  return true;//we're good until Windows x128 is released
29 #else
30  if (fnIsWow64Process == NULL) {
31  fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandleA("kernel32"),"IsWow64Process");
32  }
33  if (fnIsWow64Process == NULL) { return false; }
34 
35  BOOL bIsWow64 = FALSE;
36  if (fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) {
37  return bIsWow64;
38  }
39  return false;
40 #endif
41 }
42 
43 #else
44 
45 static char Get_OS_Version_Buf[1024];
46 const char * DSL_CC GetOSVersion() {
47  struct utsname name;
48  memset(&name, 0, sizeof(name));
49  if (uname(&name) >= 0) {
50  sprintf(Get_OS_Version_Buf, "%s %s %s on %s", name.sysname, name.version, name.release, name.machine);
51  return Get_OS_Version_Buf;
52  } else {
53  #ifdef POSIX_C_SOURCE
54  return "POSIX-compliant OS";
55  #else
56  return "Non-Windows OS";
57  #endif
58  }
59 }
60 
61 bool DSL_CC Is64Bit() {
62 #if defined(__x86_64__)
63  return true;
64 #else
65  return false;
66 #endif
67 }
68 
69 #ifdef DSL_HAVE_CPUID
70 DSL_API void DSL_CC linux_cpuid(int cpuInfo[4], int function_id) {
71  __cpuid(function_id, cpuInfo[0], cpuInfo[1], cpuInfo[2], cpuInfo[3]);
72 }
73 #endif
74 
75 #endif
76 
77 #ifdef DSL_HAVE_CPUID
78 const InstructionSet::InstructionSet_Internal InstructionSet::CPU_Rep;
79 #endif