]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/debug: Move debug functions into c file
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 13 Mar 2026 17:25:25 +0000 (18:25 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 18 Mar 2026 13:23:41 +0000 (14:23 +0100)
Having the debug functions as static inline functions throughout the
code base leads to code bloat, since they always serve the same purpose
without custom modifications.

Keep defines and everything specific to an including file in a header, but
move function bodies into their own c file.

Reduces size of util-linux installation by up to 80 KB on x86_64.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
include/debug.h
lib/Makemodule.am
lib/debug.c [new file with mode: 0644]
lib/meson.build

index b6c0e1a92ad8d6558803c79af592771593924f4e..2881910a9971b3ec9009d1bb43f3936ac710ea1e 100644 (file)
@@ -106,75 +106,11 @@ struct ul_debug_maskname {
                __UL_INIT_DEBUG_FROM_STRING(lib, pref, mask, envstr); \
        } while (0)
 
-
-
-static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
-ul_debug(const char *mesg, ...)
-{
-       va_list ap;
-       va_start(ap, mesg);
-       vfprintf(stderr, mesg, ap);
-       va_end(ap);
-       fputc('\n', stderr);
-}
-
-static inline int ul_debug_parse_mask(
-                       const struct ul_debug_maskname flagnames[],
-                       const char *mask)
-{
-       int res;
-       char *ptr;
-
-       /* let's check for a numeric mask first */
-       res = strtoul(mask, &ptr, 0);
-
-       /* perhaps it's a comma-separated string? */
-       if (ptr && *ptr && flagnames && flagnames[0].name) {
-               char *msbuf, *ms, *name;
-               res = 0;
-
-               ms = msbuf = strdup(mask);
-               if (!ms)
-                       return res;
-
-               while ((name = strtok_r(ms, ",", &ptr))) {
-                       const struct ul_debug_maskname *d;
-                       ms = ptr;
-
-                       for (d = flagnames; d && d->name; d++) {
-                               if (strcmp(name, d->name) == 0) {
-                                       res |= d->mask;
-                                       break;
-                               }
-                       }
-                       /* nothing else we can do by OR-ing the mask */
-                       if (res == 0xffff)
-                               break;
-               }
-               free(msbuf);
-       } else if (ptr && strcmp(ptr, "all") == 0)
-               res = 0xffff;
-
-       return res;
-}
-
-static inline void ul_debug_print_masks(
-                       const char *env,
-                       const struct ul_debug_maskname flagnames[])
-{
-       const struct ul_debug_maskname *d;
-
-       if (!flagnames)
-               return;
-
-       fprintf(stderr, "Available \"%s=<name>[,...]|<mask>\" debug masks:\n",
-                       env);
-       for (d = flagnames; d && d->name; d++) {
-               if (!d->help)
-                       continue;
-               fprintf(stderr, "   %-8s [0x%06x] : %s\n",
-                               d->name, d->mask, d->help);
-       }
-}
+extern void ul_debug(const char *mesg, ...)
+               __attribute__ ((__format__ (__printf__, 1, 2)));
+extern int ul_debug_parse_mask(const struct ul_debug_maskname flagnames[],
+                              const char *mask);
+extern void ul_debug_print_masks(const char *env,
+                                const struct ul_debug_maskname flagnames[]);
 
 #endif /* UTIL_LINUX_DEBUG_H */
index 5a2e9a9074c89e7a013796b50a74dfd25bbc8464..34f9c890c58bf8182682be8f3e9ce7b87affefc0 100644 (file)
@@ -21,6 +21,7 @@ libcommon_la_SOURCES = \
        lib/crc32c.c \
        lib/crc64.c \
        lib/c_strtod.c \
+       lib/debug.c \
        lib/encode.c \
        lib/env.c \
        lib/fileutils.c \
@@ -71,7 +72,7 @@ endif
 EXTRA_LTLIBRARIES += libtcolors.la
 libtcolors_la_CFLAGS = $(AM_CFLAGS)
 libtcolors_la_SOURCES = lib/colors.c lib/color-names.c include/colors.h include/color-names.h
-libtcolors_la_LIBADD =
+libtcolors_la_LIBADD = libcommon.la
 # tinfo or ncurses are optional
 if HAVE_TINFO
 libtcolors_la_LIBADD += $(TINFO_LIBS)
@@ -203,10 +204,10 @@ test_loopdev_SOURCES = lib/loopdev.c
 test_loopdev_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_LOOPDEV
 test_loopdev_LDADD = $(LDADD) libcommon.la
 
-test_netlink_SOURCES = lib/netlink.c
+test_netlink_SOURCES = lib/debug.c lib/netlink.c
 test_netlink_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_NETLINK
 
-test_netaddrq_SOURCES = lib/netaddrq.c lib/netlink.c
+test_netaddrq_SOURCES = lib/debug.c lib/netaddrq.c lib/netlink.c
 test_netaddrq_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_NETADDRQ
 endif
 
@@ -214,7 +215,7 @@ test_configs_SOURCES = lib/configs.c
 test_configs_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_CONFIGS
 test_configs_LDADD = $(LDADD) libcommon.la
 
-test_fileeq_SOURCES = lib/fileeq.c
+test_fileeq_SOURCES = lib/debug.c lib/fileeq.c
 test_fileeq_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_FILEEQ
 
 test_fileutils_SOURCES = lib/fileutils.c
diff --git a/lib/debug.c b/lib/debug.c
new file mode 100644 (file)
index 0000000..a56506c
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * No copyright is claimed.  This code is in the public domain; do with
+ * it what you wish.
+ */
+
+#include "debug.h"
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+
+void ul_debug(const char *mesg, ...)
+{
+       va_list ap;
+       va_start(ap, mesg);
+       vfprintf(stderr, mesg, ap);
+       va_end(ap);
+       fputc('\n', stderr);
+}
+
+int ul_debug_parse_mask(const struct ul_debug_maskname flagnames[],
+                       const char *mask)
+{
+       int res;
+       char *ptr;
+
+       /* let's check for a numeric mask first */
+       res = strtoul(mask, &ptr, 0);
+
+       /* perhaps it's a comma-separated string? */
+       if (ptr && *ptr && flagnames && flagnames[0].name) {
+               char *msbuf, *ms, *name;
+               res = 0;
+
+               ms = msbuf = strdup(mask);
+               if (!ms)
+                       return res;
+
+               while ((name = strtok_r(ms, ",", &ptr))) {
+                       const struct ul_debug_maskname *d;
+                       ms = ptr;
+
+                       for (d = flagnames; d && d->name; d++) {
+                               if (strcmp(name, d->name) == 0) {
+                                       res |= d->mask;
+                                       break;
+                               }
+                       }
+                       /* nothing else we can do by OR-ing the mask */
+                       if (res == 0xffff)
+                               break;
+               }
+               free(msbuf);
+       } else if (ptr && strcmp(ptr, "all") == 0)
+               res = 0xffff;
+
+       return res;
+}
+
+void ul_debug_print_masks(const char *env,
+                         const struct ul_debug_maskname flagnames[])
+{
+       const struct ul_debug_maskname *d;
+
+       if (!flagnames)
+               return;
+
+       fprintf(stderr, "Available \"%s=<name>[,...]|<mask>\" debug masks:\n",
+                       env);
+       for (d = flagnames; d && d->name; d++) {
+               if (!d->help)
+                       continue;
+               fprintf(stderr, "   %-8s [0x%06x] : %s\n",
+                               d->name, d->mask, d->help);
+       }
+}
index 35c6b2ca157faa334c61e1d0531e20d7a606e17d..c61054b9aff37541b125f13dfba27a5ed2510159 100644 (file)
@@ -7,6 +7,7 @@ lib_common_sources = '''
        crc32c.c
        crc64.c
        c_strtod.c
+       debug.c
        encode.c
        env.c
        fileutils.c