-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKernelModule.cpp
74 lines (65 loc) · 2.25 KB
/
KernelModule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* KernelModule.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dvdovenk <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/12 16:21:38 by dvdovenk #+# #+# */
/* Updated: 2017/11/12 16:21:39 by dvdovenk ### ########.fr */
/* */
/* ************************************************************************** */
#include "KernelModule.hpp"
KernelModule::KernelModule() : _moduleName("Kernel"), _moduleData()
{
_moduleData.resize(3);
updateData();
}
KernelModule::~KernelModule() { }
KernelModule::KernelModule(KernelModule const & copy)
{
_moduleData.resize(3);
*this = copy;
}
KernelModule& KernelModule::operator=(KernelModule const & copy)
{
if (this != ©)
{
_moduleData[0] = copy.getInfo("OS");
_moduleData[1] = copy.getInfo("type");
_moduleData[2] = copy.getInfo("bit");
}
return (*this);
}
std::string KernelModule::getInfo(std::string data) const
{
if (data == "OS")
return (_moduleData[0]);
else if (data == "type")
return (_moduleData[1]);
else if (data == "bit")
return (_moduleData[2]);
return ("no");
}
void KernelModule::updateData()
{
char buffer[256];
std::stringstream ss;
FILE *in;
size_t bufferlen;
in = popen("sw_vers | awk -F':t' '{print $1}' | cut -d$'\t' -f2 | paste -d ' ' - - - | tr -d '\n'", "r");
ss << "OS Version: ";
while (fgets(buffer, sizeof(buffer), in) != NULL)
ss << buffer;
_moduleData[0] = ss.str();
ss.str(std::string());
bufferlen = 256;
sysctlbyname("kern.ostype", &buffer, &bufferlen, NULL, 0);
ss << "OS Type: " << buffer;
_moduleData[1] = ss.str();
ss.str(std::string());
bufferlen = 256;
sysctlbyname("hw.machine", &buffer, &bufferlen, NULL, 0);
ss << "Bit System: " << buffer;
_moduleData[2] = ss.str();
}