grub-devel
[Top][All Lists]
Advanced

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

[PATCH v2 04/12] kern: Add grub_debug_enabled()


From: Javier Martinez Canillas
Subject: [PATCH v2 04/12] kern: Add grub_debug_enabled()
Date: Wed, 4 Mar 2020 12:58:43 +0100

From: Peter Jones <address@hidden>

Add a grub_debug_enabled() helper function instead of open coding it.

Signed-off-by: Peter Jones <address@hidden>
Signed-off-by: Javier Martinez Canillas <address@hidden>
Reviewed-by: Daniel Kiper <address@hidden>
---

 grub-core/kern/misc.c | 21 ++++++++++++++++-----
 include/grub/misc.h   |  1 +
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 76e7fb22872..d205fb1342e 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -158,17 +158,28 @@ int grub_err_printf (const char *fmt, ...)
 __attribute__ ((alias("grub_printf")));
 #endif
 
+int
+grub_debug_enabled (const char * condition)
+{
+  const char *debug;
+
+  debug = grub_env_get ("debug");
+  if (!debug)
+    return 0;
+
+  if (grub_strword (debug, "all") || grub_strword (debug, condition))
+    return 1;
+
+  return 0;
+}
+
 void
 grub_real_dprintf (const char *file, const int line, const char *condition,
                   const char *fmt, ...)
 {
   va_list args;
-  const char *debug = grub_env_get ("debug");
-
-  if (! debug)
-    return;
 
-  if (grub_strword (debug, "all") || grub_strword (debug, condition))
+  if (grub_debug_enabled (condition))
     {
       grub_printf ("%s:%d: ", file, line);
       va_start (args, fmt);
diff --git a/include/grub/misc.h b/include/grub/misc.h
index ee48eb7a726..585c2a7644c 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -322,6 +322,7 @@ grub_puts (const char *s)
 }
 
 int EXPORT_FUNC(grub_puts_) (const char *s);
+int EXPORT_FUNC(grub_debug_enabled) (const char *condition);
 void EXPORT_FUNC(grub_real_dprintf) (const char *file,
                                      const int line,
                                      const char *condition,
-- 
2.24.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]