[gnome-builder/wip/chergert/pipeline: 2/43] posix: add ide_get_system_type()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/pipeline: 2/43] posix: add ide_get_system_type()
- Date: Fri, 3 Feb 2017 22:06:36 +0000 (UTC)
commit e9ae44ad9bd2d24ab1461f7efcfb07d481675bcb
Author: Christian Hergert <chergert redhat com>
Date: Fri Feb 3 12:12:14 2017 -0800
posix: add ide_get_system_type()
This is a helper to get the host device triplet. It simplifies comparing
an IdeDevice against the system-type.
libide/local/ide-local-device.c | 35 +++--------------------------------
libide/util/ide-posix.c | 36 ++++++++++++++++++++++++++++++++++++
libide/util/ide-posix.h | 9 +++++----
3 files changed, 44 insertions(+), 36 deletions(-)
---
diff --git a/libide/local/ide-local-device.c b/libide/local/ide-local-device.c
index 99f468e..653a4ad 100644
--- a/libide/local/ide-local-device.c
+++ b/libide/local/ide-local-device.c
@@ -21,7 +21,8 @@
#include <string.h>
#include <sys/utsname.h>
-#include "ide-local-device.h"
+#include "local/ide-local-device.h"
+#include "util/ide-posix.h"
typedef struct
{
@@ -30,36 +31,6 @@ typedef struct
G_DEFINE_TYPE_WITH_PRIVATE (IdeLocalDevice, ide_local_device, IDE_TYPE_DEVICE)
-static gchar *
-get_system_type (void)
-{
- g_autofree gchar *os_lower = NULL;
- const gchar *machine = NULL;
- struct utsname u;
-
- if (uname (&u) < 0)
- return g_strdup ("unknown");
-
- os_lower = g_utf8_strdown (u.sysname, -1);
-
- /* config.sub doesn't accept amd64-OS */
- machine = strcmp (u.machine, "amd64") ? u.machine : "x86_64";
-
- /*
- * TODO: Clearly we want to discover "gnu", but that should be just fine
- * for a default until we try to actually run on something non-gnu.
- * Which seems unlikely at the moment. If you run FreeBSD, you can
- * probably fix this for me :-) And while you're at it, make the
- * uname() call more portable.
- */
-
-#ifdef __GLIBC__
- return g_strdup_printf ("%s-%s-%s", machine, os_lower, "gnu");
-#else
- return g_strdup_printf ("%s-%s", machine, os_lower);
-#endif
-}
-
static const gchar *
ide_local_device_get_system_type (IdeDevice *device)
{
@@ -99,7 +70,7 @@ ide_local_device_init (IdeLocalDevice *self)
{
IdeLocalDevicePrivate *priv = ide_local_device_get_instance_private (self);
- priv->system_type = get_system_type ();
+ priv->system_type = g_strdup (ide_get_system_type ());
ide_device_set_display_name (IDE_DEVICE (self), g_get_host_name ());
ide_device_set_id (IDE_DEVICE (self), "local");
diff --git a/libide/util/ide-posix.c b/libide/util/ide-posix.c
index 5605001..3bbb495 100644
--- a/libide/util/ide-posix.c
+++ b/libide/util/ide-posix.c
@@ -25,6 +25,42 @@
#include "ide-posix.h"
+const gchar *
+ide_get_system_type (void)
+{
+ static gchar *system_type;
+ g_autofree gchar *os_lower = NULL;
+ const gchar *machine = NULL;
+ struct utsname u;
+
+ if (system_type != NULL)
+ return system_type;
+
+ if (uname (&u) < 0)
+ return g_strdup ("unknown");
+
+ os_lower = g_utf8_strdown (u.sysname, -1);
+
+ /* config.sub doesn't accept amd64-OS */
+ machine = strcmp (u.machine, "amd64") ? u.machine : "x86_64";
+
+ /*
+ * TODO: Clearly we want to discover "gnu", but that should be just fine
+ * for a default until we try to actually run on something non-gnu.
+ * Which seems unlikely at the moment. If you run FreeBSD, you can
+ * probably fix this for me :-) And while you're at it, make the
+ * uname() call more portable.
+ */
+
+#ifdef __GLIBC__
+ system_type = g_strdup_printf ("%s-%s-%s", machine, os_lower, "gnu");
+#else
+ system_type = g_strdup_printf ("%s-%s", machine, os_lower);
+#endif
+
+ return system_type;
+}
+
gchar *
ide_get_system_arch (void)
{
diff --git a/libide/util/ide-posix.h b/libide/util/ide-posix.h
index b0bb05f..328f544 100644
--- a/libide/util/ide-posix.h
+++ b/libide/util/ide-posix.h
@@ -23,10 +23,11 @@
G_BEGIN_DECLS
-gchar *ide_get_system_arch (void);
-gsize ide_get_system_page_size (void) G_GNUC_CONST;
-gchar *ide_path_collapse (const gchar *path);
-gchar *ide_path_expand (const gchar *path);
+gchar *ide_get_system_arch (void);
+const gchar *ide_get_system_type (void);
+gsize ide_get_system_page_size (void) G_GNUC_CONST;
+gchar *ide_path_collapse (const gchar *path);
+gchar *ide_path_expand (const gchar *path);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]