[gnome-software/wip/lantw/freebsd-memory-total: 327/328] Implement gs_utils_get_memory_total for FreeBSD
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/lantw/freebsd-memory-total: 327/328] Implement gs_utils_get_memory_total for FreeBSD
- Date: Tue, 17 Apr 2018 11:48:24 +0000 (UTC)
commit 8e6f1603131c191c6c279416724b642d787d3cc4
Author: Ting-Wei Lan <lantw src gnome org>
Date: Wed Jan 31 03:30:33 2018 +0800
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.
lib/gs-utils.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
---
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index cfc556c3..5dd7d99b 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -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
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]