[gnome-software/wip/lantw/freebsd-memory-total] Implement gs_utils_get_memory_total for FreeBSD
- From: Ting-Wei Lan <lantw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/lantw/freebsd-memory-total] Implement gs_utils_get_memory_total for FreeBSD
- Date: Tue, 30 Jan 2018 19:43:51 +0000 (UTC)
commit abf0635a7d73bb6c85f47c5a34fbdbb7654bb10b
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 9b754ed9..8404f2ca 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -38,7 +38,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>
@@ -1035,9 +1041,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
}
/* vim: set noexpandtab: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]