[tracker] Implement get_memory_total() on OpenBSD.



commit a5dcf74772ad7800100905d93a11debf67644a38
Author: Antoine Jacoutot <ajacoutot gnome org>
Date:   Mon Apr 29 17:03:36 2013 +0200

    Implement get_memory_total() on OpenBSD.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697719

 src/libtracker-common/tracker-os-dependant-unix.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-common/tracker-os-dependant-unix.c 
b/src/libtracker-common/tracker-os-dependant-unix.c
index 5c36c71..79eb837 100644
--- a/src/libtracker-common/tracker-os-dependant-unix.c
+++ b/src/libtracker-common/tracker-os-dependant-unix.c
@@ -26,6 +26,11 @@
 #include <unistd.h>
 #include <sys/resource.h>
 
+#if defined (__OpenBSD__)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
 #include <glib.h>
 
 #include "tracker-log.h"
@@ -225,6 +230,7 @@ tracker_create_permission_string (struct stat finfo)
 static glong
 get_memory_total (void)
 {
+#if !defined (__OpenBSD__)
        GError      *error = NULL;
        const gchar *filename;
        gchar       *contents = NULL;
@@ -258,6 +264,20 @@ get_memory_total (void)
                }
                g_free (contents);
        }
+#else /* OpenBSD */
+       glong total = 0;
+       int64_t physmem;
+       size_t len;
+       static gint mib[] = { CTL_HW, HW_PHYSMEM64 };
+
+       len = sizeof (physmem);
+
+       if (sysctl (mib, G_N_ELEMENTS (mib), &physmem, &len, NULL, 0) == -1) {
+               g_critical ("Couldn't get memory information: %d", errno);
+       } else {
+               total = physmem;
+       }
+#endif /* !OpenBSD */
 
        return total;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]