Group :: Sistema/Kernel e hardware
RPM: fuse-cryfs
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
Patch: fuse-cryfs-glibc-compat.patch
Download
Download
diff --git a/fuse-cryfs/src/cpp-utils/system/get_total_memory.cpp b/fuse-cryfs/src/cpp-utils/system/get_total_memory.cpp
index 83abe6c..85f197c 100644
--- a/fuse-cryfs/src/cpp-utils/system/get_total_memory.cpp
+++ b/fuse-cryfs/src/cpp-utils/system/get_total_memory.cpp
@@ -1,27 +1,58 @@
#include "get_total_memory.h"
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#include <unistd.h>
#include <stdexcept>
+#include <string>
-namespace cpputils{
- namespace system {
- uint64_t get_total_memory() {
- uint64_t mem;
#if defined(__APPLE__)
- size_t size = sizeof(mem);
- int result = sysctlbyname("hw.memsize", &mem, &size, nullptr, 0);
- if (0 != result) {
- throw std::runtime_error("sysctlbyname syscall failed");
- }
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+namespace cpputils {
+ namespace system {
+ uint64_t get_total_memory() {
+ uint64_t mem;
+ size_t size = sizeof(mem);
+ int result = sysctlbyname("hw.memsize", &mem, &size, nullptr, 0);
+ if (0 != result) {
+ throw std::runtime_error("sysctlbyname syscall failed");
+ }
+ return mem;
+ }
+ }
+}
+
#elif defined(__linux__) || defined(__FreeBSD__)
- long numRAMPages = sysconf(_SC_PHYS_PAGES);
- long pageSize = sysconf(_SC_PAGESIZE);
- mem = numRAMPages * pageSize;
+
+#include <unistd.h>
+
+namespace cpputils {
+ namespace system {
+ uint64_t get_total_memory() {
+ long numRAMPages = sysconf(_SC_PHYS_PAGES);
+ long pageSize = sysconf(_SC_PAGESIZE);
+ return numRAMPages * pageSize;
+ }
+ }
+}
+
+#elif defined(_MSC_VER)
+
+#include <Windows.h>
+
+namespace cpputils {
+ namespace system {
+ uint64_t get_total_memory() {
+ MEMORYSTATUSEX status;
+ status.dwLength = sizeof(status);
+ if (!::GlobalMemoryStatusEx(&status)) {
+ throw std::runtime_error("Couldn't get system memory information. Error code: " + std::to_string(GetLastError()));
+ }
+ return status.ullTotalPhys;
+ }
+ }
+}
+
#else
-#error Not supported on windows yet, TODO http://stackoverflow.com/a/2513561/829568
+#error Unsupported platform
#endif
- return mem;
- }
- }
-}
+