[retro-gtk] shared: Add retro_is_debug()



commit 26e4146a8914a04fd4463255df468aa86f35dbb3
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Mon Dec 14 19:51:37 2020 +0100

    shared: Add retro_is_debug()
    
    This will help printing debug logs when RETRO_DEBUG is set to 1.

 doc/meson.build              |  1 +
 shared/meson.build           |  1 +
 shared/retro-debug-private.h | 15 +++++++++++++++
 shared/retro-debug.c         | 21 +++++++++++++++++++++
 4 files changed, 38 insertions(+)
---
diff --git a/doc/meson.build b/doc/meson.build
index 3eff925..2403ac5 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -11,6 +11,7 @@ private_headers = [
   'retro-controller-iterator-private.h',
   'retro-controller-state-private.h',
   'retro-core-view-controller-private.h',
+  'retro-debug-private.h',
   'retro-framebuffer-private.h',
   'retro-gl-display-private.h',
   'retro-glsl-filter-private.h',
diff --git a/shared/meson.build b/shared/meson.build
index dc7e0ac..8757d06 100644
--- a/shared/meson.build
+++ b/shared/meson.build
@@ -19,6 +19,7 @@ shared_sources = files([
   'retro-controller-codes.c',
   'retro-controller-state.c',
   'retro-controller-type.c',
+  'retro-debug.c',
   'retro-framebuffer.c',
   'retro-input.c',
   'retro-memfd.c',
diff --git a/shared/retro-debug-private.h b/shared/retro-debug-private.h
new file mode 100644
index 0000000..e70da9f
--- /dev/null
+++ b/shared/retro-debug-private.h
@@ -0,0 +1,15 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#pragma once
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean retro_is_debug (void);
+
+G_END_DECLS
diff --git a/shared/retro-debug.c b/shared/retro-debug.c
new file mode 100644
index 0000000..b5deea7
--- /dev/null
+++ b/shared/retro-debug.c
@@ -0,0 +1,21 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-debug-private.h"
+
+gboolean
+retro_is_debug (void)
+{
+  static gsize init = 0;
+  gboolean debug = FALSE;
+
+  if (g_once_init_enter (&init)) {
+    g_auto(GStrv) envp = g_get_environ ();
+    const gchar *env_value = g_environ_getenv (envp, "RETRO_DEBUG");
+
+    debug = (g_strcmp0 ("1", env_value) == 0);
+
+    g_once_init_leave (&init, 1);
+  }
+
+  return debug;
+}


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