summaryrefslogtreecommitdiffstats
path: root/libraries/systeminfo/src/sys_unix.cpp
blob: 866c9fdbfa2f5f4091ee25ace4b4cdc2f6ec469e (plain)
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
#include "sys.h"

#include <sys/utsname.h>
#include <fstream>

Sys::KernelInfo Sys::getKernelInfo()
{
	Sys::KernelInfo out;
	struct utsname buf;
	uname(&buf);
	out.kernelName = buf.sysname;
	out.kernelVersion = buf.release;
	return out;
}

uint64_t Sys::getSystemRam()
{
	std::string token;
	std::ifstream file("/proc/meminfo");
	while(file >> token)
	{
		if(token == "MemTotal:")
		{
			uint64_t mem;
			if(file >> mem)
			{
				return mem * 1024ull;
			}
			else
			{
				return 0;
			}
		}
		// ignore rest of the line
		file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	}
	return 0; // nothing found
}

bool Sys::isCPU64bit()
{
	return isSystem64bit();
}

bool Sys::isSystem64bit()
{
	// kernel build arch on linux
	return QSysInfo::currentCpuArchitecture() == "x86_64";
}