]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
debug: Use macro definitions more often
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 3 Apr 2026 08:52:06 +0000 (10:52 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 7 Apr 2026 10:09:29 +0000 (12:09 +0200)
Improve readability by using macro definitions instead of explicitly
concatenating variable names in various places.

While at it, fixed formatting.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
include/debug.h

index cf560ba0a2841e5e84bcc656b4aacdeb25610117..6f86224c2c308836a89457003eee295268a9243e 100644 (file)
@@ -56,8 +56,9 @@ struct ul_debug_maskname {
  */
 
 #define UL_DEBUG_EMPTY_MASKNAMES {{ NULL, 0, NULL }}
-#define UL_DEBUG_DEFINE_MASKNAMES(lib) static const struct ul_debug_maskname lib ## _masknames[]
 #define UL_DEBUG_MASKNAMES(lib)        lib ## _masknames
+#define UL_DEBUG_DEFINE_MASKNAMES(lib) \
+       static const struct ul_debug_maskname UL_DEBUG_MASKNAMES(lib)[]
 
 #define UL_DEBUG_MASK(lib)         lib ## _debug_mask
 #define UL_DEBUG_DEFINE_MASK(lib)  unsigned UL_DEBUG_MASK(lib)
@@ -72,8 +73,8 @@ struct ul_debug_maskname {
 
 #define __UL_DBG_OBJ(lib, pref, flag, h, x) \
        do { \
-               if ((pref ## flag) & lib ## _debug_mask) { \
-                       ul_debug_prefix(# lib, # flag, h, lib ## _debug_mask); \
+               if ((pref ## flag) & UL_DEBUG_MASK(lib)) { \
+                       ul_debug_prefix(# lib, # flag, h, UL_DEBUG_MASK(lib)); \
                        x; \
                } \
        } while (0)
@@ -83,34 +84,33 @@ struct ul_debug_maskname {
 
 #define __UL_DBG_CALL(lib, pref, flag, x) \
        do { \
-               if ((pref ## flag) & lib ## _debug_mask) { \
+               if ((pref ## flag) & UL_DEBUG_MASK(lib)) { \
                        x; \
                } \
        } while (0)
 
 #define __UL_DBG_FLUSH(lib, pref) \
        do { \
-               if (lib ## _debug_mask && \
-                   lib ## _debug_mask != pref ## INIT) { \
+               if (UL_DEBUG_MASK(lib) && UL_DEBUG_MASK(lib) != pref ## INIT) { \
                        fflush(stderr); \
                } \
        } while (0)
 
 #define __UL_INIT_DEBUG_FROM_STRING(lib, pref, mask, str) \
        do { \
-               if (lib ## _debug_mask & pref ## INIT) \
-               ; \
-               else if (!mask && str) \
-                       lib ## _debug_mask = ul_debug_parse_mask(lib ## _masknames, str); \
-               else \
-                       lib ## _debug_mask = mask; \
-               if (lib ## _debug_mask) { \
+               if (UL_DEBUG_MASK(lib) & pref ## INIT) \
+                       ; \
+               else if (!mask && str) \
+                       UL_DEBUG_MASK(lib) = ul_debug_parse_mask(UL_DEBUG_MASKNAMES(lib), str); \
+               else \
+                       UL_DEBUG_MASK(lib) = mask; \
+               if (UL_DEBUG_MASK(lib)) { \
                        if (is_privileged_execution()) { \
-                               lib ## _debug_mask |= __UL_DEBUG_FL_NOADDR; \
+                               UL_DEBUG_MASK(lib) |= __UL_DEBUG_FL_NOADDR; \
                                fprintf(stderr, "%d: %s: don't print memory addresses (SUID executable).\n", getpid(), # lib); \
                        } \
                } \
-               lib ## _debug_mask |= pref ## INIT; \
+               UL_DEBUG_MASK(lib) |= pref ## INIT; \
        } while (0)