Coverage Report

Created: 2026-09-14 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/knot-dns/src/libknot/lookup.h
Line
Count
Source
1
/*  Copyright (C) CZ.NIC, z.s.p.o. and contributors
2
 *  SPDX-License-Identifier: GPL-2.0-or-later
3
 *  For more information, see <https://www.knot-dns.cz/>
4
 */
5
6
/*!
7
 * \file
8
 *
9
 * \brief A general purpose lookup table.
10
 *
11
 * \addtogroup libknot
12
 * @{
13
 */
14
15
#pragma once
16
17
#include <string.h>
18
#include <strings.h>
19
20
/*!
21
 * \brief A general purpose lookup table.
22
 */
23
typedef struct knot_lookup {
24
  int id;
25
  const char *name;
26
} knot_lookup_t;
27
28
/*!
29
 * \brief Looks up the given name in the lookup table.
30
 *
31
 * \param table Lookup table.
32
 * \param name Name to look up.
33
 *
34
 * \return Item in the lookup table with the given name or NULL if no such is
35
 *         present.
36
 */
37
inline static const knot_lookup_t *knot_lookup_by_name(const knot_lookup_t *table, const char *name)
38
0
{
39
0
  if (table == NULL || name == NULL) {
40
0
    return NULL;
41
0
  }
42
0
43
0
  while (table->name != NULL) {
44
0
    if (strcasecmp(name, table->name) == 0) {
45
0
      return table;
46
0
    }
47
0
    table++;
48
0
  }
49
0
50
0
  return NULL;
51
0
}
Unexecuted instantiation: pkt.c:knot_lookup_by_name
Unexecuted instantiation: opt.c:knot_lookup_by_name
Unexecuted instantiation: codes.c:knot_lookup_by_name
52
53
/*!
54
 * \brief Looks up the given id in the lookup table.
55
 *
56
 * \param table Lookup table.
57
 * \param id ID to look up.
58
 *
59
 * \return Item in the lookup table with the given id or NULL if no such is
60
 *         present.
61
 */
62
inline static const knot_lookup_t *knot_lookup_by_id(const knot_lookup_t *table, int id)
63
0
{
64
0
  if (table == NULL) {
65
0
    return NULL;
66
0
  }
67
68
0
  while (table->name != NULL) {
69
0
    if (table->id == id) {
70
0
      return table;
71
0
    }
72
0
    table++;
73
0
  }
74
75
0
  return NULL;
76
0
}
Unexecuted instantiation: pkt.c:knot_lookup_by_id
Unexecuted instantiation: opt.c:knot_lookup_by_id
Unexecuted instantiation: codes.c:knot_lookup_by_id
77
78
/*! @} */