Commit 8e6f1603 authored by Ting-Wei Lan's avatar Ting-Wei Lan Committed by Richard Hughes

Implement gs_utils_get_memory_total for FreeBSD

sysinfo is a Linux-specific system call which is not available on other
operating systems. This commit adds an implementation using the value
come from 'sysctl hw.physmem' for FreeBSD.
parent 20a6ffb4
......@@ -39,7 +39,13 @@
#include <string.h>
#include <glib/gstdio.h>
#include <json-glib/json-glib.h>
#if defined(__linux__)
#include <sys/sysinfo.h>
#elif defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#ifdef HAVE_POLKIT
#include <polkit/polkit.h>
......@@ -1036,9 +1042,17 @@ gs_utils_is_low_resolution (GtkWidget *toplevel)
guint
gs_utils_get_memory_total (void)
{
#if defined(__linux__)
struct sysinfo si = { 0 };
sysinfo (&si);
return si.totalram / MB_IN_BYTES / si.mem_unit;
#elif defined(__FreeBSD__)
unsigned long physmem;
sysctl ((int[]){ CTL_HW, HW_PHYSMEM }, 2, &physmem, &(size_t){ sizeof (physmem) }, NULL, 0);
return physmem / MB_IN_BYTES;
#else
#error "Please implement gs_utils_get_memory_total for your system."
#endif
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment