Coverage Report

Created: 2026-04-11 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/util-linux/lib/debug.c
Line
Count
Source
1
/*
2
 * No copyright is claimed.  This code is in the public domain; do with
3
 * it what you wish.
4
 */
5
6
#include "debug.h"
7
8
#include <stdarg.h>
9
#include <stdlib.h>
10
#include <stdio.h>
11
#include <string.h>
12
13
14
void ul_debug(const char *mesg, ...)
15
0
{
16
0
  va_list ap;
17
0
  va_start(ap, mesg);
18
0
  vfprintf(stderr, mesg, ap);
19
0
  va_end(ap);
20
0
  fputc('\n', stderr);
21
0
}
22
23
void ul_debug_prefix(const char *lib, const char *flag,
24
         const void *handle, unsigned mask)
25
0
{
26
0
  fprintf(stderr, "%d: %s: %8s: ", getpid(), lib, flag);
27
0
  if (handle && !(mask & __UL_DEBUG_FL_NOADDR))
28
0
    fprintf(stderr, "[%p]: ", handle);
29
0
}
30
31
unsigned ul_debug_parse_mask(const struct ul_debug_maskname flagnames[],
32
           const char *mask)
33
0
{
34
0
  unsigned res;
35
0
  char *ptr;
36
37
  /* let's check for a numeric mask first */
38
0
  res = strtoul(mask, &ptr, 0);
39
40
  /* perhaps it's a comma-separated string? */
41
0
  if (ptr && *ptr && flagnames && flagnames[0].name) {
42
0
    char *msbuf, *ms, *name;
43
0
    res = 0;
44
45
0
    ms = msbuf = strdup(mask);
46
0
    if (!ms)
47
0
      return res;
48
49
0
    while ((name = strtok_r(ms, ",", &ptr))) {
50
0
      const struct ul_debug_maskname *d;
51
0
      ms = ptr;
52
53
0
      for (d = flagnames; d && d->name; d++) {
54
0
        if (strcmp(name, d->name) == 0) {
55
0
          res |= d->mask;
56
0
          break;
57
0
        }
58
0
      }
59
      /* nothing else we can do by OR-ing the mask */
60
0
      if (res == UL_DEBUG_ALL)
61
0
        break;
62
0
    }
63
0
    free(msbuf);
64
0
  } else if (ptr && strcmp(ptr, "all") == 0)
65
0
    res = UL_DEBUG_ALL;
66
67
0
  return res;
68
0
}
69
70
void ul_debug_print_masks(const char *env,
71
        const struct ul_debug_maskname flagnames[])
72
0
{
73
0
  const struct ul_debug_maskname *d;
74
75
0
  if (!flagnames)
76
0
    return;
77
78
0
  fprintf(stderr, "Available \"%s=<name>[,...]|<mask>\" debug masks:\n",
79
0
      env);
80
0
  for (d = flagnames; d && d->name; d++) {
81
0
    if (!d->help)
82
0
      continue;
83
0
    fprintf(stderr, "   %-8s [0x%06x] : %s\n",
84
0
        d->name, d->mask, d->help);
85
0
  }
86
0
}