libcommon: move event.c to libcommon-lgpl
[lttng-tools.git] / src / common / event.cpp
CommitLineData
76fcf151 1/*
ab5be9fa 2 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
76fcf151 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
76fcf151 5 *
76fcf151
JG
6 */
7
8#include <lttng/event-internal.h>
9#include <common/error.h>
10
76fcf151
JG
11struct lttng_event *lttng_event_copy(const struct lttng_event *event)
12{
13 struct lttng_event *new_event;
14 struct lttng_event_extended *new_event_extended;
15
a6bc4ca9 16 new_event = (lttng_event *) zmalloc(sizeof(*event));
76fcf151
JG
17 if (!new_event) {
18 PERROR("Error allocating event structure");
19 goto end;
20 }
21
22 /* Copy the content of the old event. */
23 memcpy(new_event, event, sizeof(*event));
24
25 /*
26 * We need to create a new extended since the previous pointer is now
27 * invalid.
28 */
a6bc4ca9 29 new_event_extended = (lttng_event_extended *) zmalloc(sizeof(*new_event_extended));
76fcf151
JG
30 if (!new_event_extended) {
31 PERROR("Error allocating event extended structure");
32 goto error;
33 }
34
35 new_event->extended.ptr = new_event_extended;
36end:
37 return new_event;
38error:
39 free(new_event);
37750a61 40 new_event = NULL;
76fcf151
JG
41 goto end;
42}
This page took 0.037783 seconds and 4 git commands to generate.