X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fevent.cpp;fp=src%2Fcommon%2Fevent.cpp;h=6b22fecf52799f1bd7a26fc97f84d5ab0db18fef;hp=0000000000000000000000000000000000000000;hb=a6bc4ca9d659caf016ef932fcd944029737ac57c;hpb=97535efaa975ca52bf02c2d5e76351bfd2e3defa diff --git a/src/common/event.cpp b/src/common/event.cpp new file mode 100644 index 000000000..6b22fecf5 --- /dev/null +++ b/src/common/event.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#include +#include + +struct lttng_event *lttng_event_copy(const struct lttng_event *event) +{ + struct lttng_event *new_event; + struct lttng_event_extended *new_event_extended; + + new_event = (lttng_event *) zmalloc(sizeof(*event)); + if (!new_event) { + PERROR("Error allocating event structure"); + goto end; + } + + /* Copy the content of the old event. */ + memcpy(new_event, event, sizeof(*event)); + + /* + * We need to create a new extended since the previous pointer is now + * invalid. + */ + new_event_extended = (lttng_event_extended *) zmalloc(sizeof(*new_event_extended)); + if (!new_event_extended) { + PERROR("Error allocating event extended structure"); + goto error; + } + + new_event->extended.ptr = new_event_extended; +end: + return new_event; +error: + free(new_event); + new_event = NULL; + goto end; +}