#include <lttng/action/path-internal.hpp>
+namespace {
struct lttng_action_path_comm {
uint32_t index_count;
uint64_t indexes[];
} LTTNG_PACKED;
+} /* namespace */
struct lttng_action_path *lttng_action_path_create(
const uint64_t *indexes, size_t index_count)
goto error;
}
- path = (lttng_action_path *) zmalloc(sizeof(*path));
+ path = zmalloc<lttng_action_path>();
if (!path) {
goto error;
}
}
int lttng_action_path_copy(const struct lttng_action_path *src,
- struct lttng_action_path *dst)
+ struct lttng_action_path **dst)
{
int ret;
- size_t i, src_count;
+ struct lttng_action_path *new_path;
LTTNG_ASSERT(src);
LTTNG_ASSERT(dst);
- lttng_dynamic_array_init(&dst->indexes, sizeof(uint64_t), NULL);
- src_count = lttng_dynamic_array_get_count(&src->indexes);
-
- for (i = 0; i < src_count; i++) {
- const void *index = lttng_dynamic_array_get_element(
- &src->indexes, i);
-
- ret = lttng_dynamic_array_add_element(&dst->indexes, index);
- if (ret) {
- goto error;
- }
+ new_path = lttng_action_path_create(
+ (uint64_t *) lttng_dynamic_array_get_element(
+ &src->indexes, 0),
+ lttng_dynamic_array_get_count(&src->indexes));
+ if (!new_path) {
+ ret = -1;
+ } else {
+ ret = 0;
+ *dst = new_path;
}
- ret = 0;
- goto end;
-error:
- lttng_dynamic_array_reset(&dst->indexes);
-end:
return ret;
}
goto end;
}
- comm = {
- .index_count = (uint32_t) index_count,
- };
+ comm.index_count = (uint32_t) index_count;
ret = lttng_dynamic_buffer_append(&payload->buffer,
&comm,
sizeof(struct lttng_action_path_comm));