+ if (bt_object_get_ref_count(event)) {
+ /*
+ * The event is being orphaned, but it must guarantee the
+ * existence of its event class for the duration of its
+ * lifetime.
+ */
+ bt_get(event->event_class);
+ BT_PUT(event->base.parent);
+ } else {
+ bt_object_release(event);
+ }
+}
+
+static
+int create_stream_file(struct bt_ctf_writer *writer,
+ struct bt_ctf_stream *stream)
+{
+ int fd;
+ GString *filename = g_string_new(stream->stream_class->name->str);
+
+ if (stream->stream_class->name->len == 0) {
+ int64_t ret;
+
+ ret = bt_ctf_stream_class_get_id(stream->stream_class);
+ if (ret < 0) {
+ fd = -1;
+ goto error;
+ }
+
+ g_string_printf(filename, "stream_%" PRId64, ret);
+ }
+
+ g_string_append_printf(filename, "_%" PRIu32, stream->id);
+ fd = openat(writer->trace_dir_fd, filename->str,
+ O_RDWR | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+error:
+ g_string_free(filename, TRUE);
+ return fd;
+}
+
+static
+int set_stream_fd(struct bt_ctf_stream *stream, int fd)
+{
+ int ret = 0;
+
+ if (stream->pos.fd != -1) {
+ ret = -1;
+ goto end;
+ }
+
+ ctf_init_pos(&stream->pos, NULL, fd, O_RDWR);
+ stream->pos.fd = fd;
+end:
+ return ret;