Run clang-format on the whole tree
[lttng-tools.git] / src / common / filter.cpp
1 /*
2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #include "filter.hpp"
9
10 #include <stddef.h>
11
12 struct bytecode_symbol_iterator {
13 /* No ownership of bytecode is taken. */
14 char *bytecode;
15 size_t offset, len;
16 };
17
18 struct bytecode_symbol_iterator *bytecode_symbol_iterator_create(struct lttng_bytecode *bytecode)
19 {
20 struct bytecode_symbol_iterator *it = NULL;
21
22 if (!bytecode) {
23 goto end;
24 }
25
26 it = zmalloc<bytecode_symbol_iterator>();
27 if (!it) {
28 goto end;
29 }
30
31 it->bytecode = bytecode->data;
32 it->offset = bytecode->reloc_table_offset;
33 it->len = bytecode->len;
34 end:
35 return it;
36 }
37
38 int bytecode_symbol_iterator_next(struct bytecode_symbol_iterator *it)
39 {
40 int ret;
41 size_t len;
42
43 if (!it || it->offset >= it->len) {
44 ret = -1;
45 goto end;
46 }
47
48 len = strlen(it->bytecode + it->offset + sizeof(uint16_t)) + 1;
49 it->offset += len + sizeof(uint16_t);
50 ret = it->offset >= it->len ? -1 : 0;
51 end:
52 return ret;
53 }
54
55 int bytecode_symbol_iterator_get_type(struct bytecode_symbol_iterator *it)
56 {
57 int ret;
58
59 if (!it) {
60 ret = -1;
61 goto end;
62 }
63
64 ret = *((uint16_t *) (it->bytecode + it->offset));
65 end:
66 return ret;
67 }
68
69 const char *bytecode_symbol_iterator_get_name(struct bytecode_symbol_iterator *it)
70 {
71 const char *ret = NULL;
72
73 if (!it) {
74 goto end;
75 }
76
77 ret = it->bytecode + it->offset + sizeof(uint16_t);
78 end:
79 return ret;
80 }
81
82 void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it)
83 {
84 free(it);
85 }
This page took 0.031786 seconds and 5 git commands to generate.