Rename C++ header files to .hpp
[lttng-tools.git] / src / common / filter.cpp
CommitLineData
71a559f8 1/*
ab5be9fa 2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
71a559f8 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
71a559f8 5 *
71a559f8
JG
6 */
7
c9e313bc 8#include "filter.hpp"
71a559f8
JG
9#include <stddef.h>
10
11struct bytecode_symbol_iterator {
12 /* No ownership of bytecode is taken. */
13 char *bytecode;
14 size_t offset, len;
15};
16
17struct bytecode_symbol_iterator *bytecode_symbol_iterator_create(
2b00d462 18 struct lttng_bytecode *bytecode)
71a559f8
JG
19{
20 struct bytecode_symbol_iterator *it = NULL;
21
22 if (!bytecode) {
23 goto end;
24 }
25
a6bc4ca9 26 it = (bytecode_symbol_iterator *) zmalloc(sizeof(*it));
71a559f8
JG
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;
34end:
35 return it;
36}
37
38int 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;
51end:
52 return ret;
53}
54
55int 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));
65end:
66 return ret;
67 }
68
69const char *bytecode_symbol_iterator_get_name(
70 struct bytecode_symbol_iterator *it)
71{
72 const char *ret = NULL;
73
74 if (!it) {
75 goto end;
76 }
77
78 ret = it->bytecode + it->offset + sizeof(uint16_t);
79end:
80 return ret;
81}
82
83void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it)
84{
85 free(it);
86}
This page took 0.049772 seconds and 4 git commands to generate.