From db88129c81a714a2235705565d3857466a4831be Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sat, 8 Jul 2023 11:19:02 -0700 Subject: [PATCH] libsysprof-capture: add API to duplicate underlying write FD This is useful for use in our other libraries that may need access to these to create document loaders for a completed writer. --- src/libsysprof-capture/sysprof-capture-writer.c | 11 +++++++++++ src/libsysprof-capture/sysprof-capture-writer.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c index 1e3f57e4..4b703d3d 100644 --- a/src/libsysprof-capture/sysprof-capture-writer.c +++ b/src/libsysprof-capture/sysprof-capture-writer.c @@ -1704,3 +1704,14 @@ _sysprof_capture_writer_add_raw (SysprofCaptureWriter *self, return true; } + +int +_sysprof_capture_writer_dup_fd (SysprofCaptureWriter *self) +{ + assert (self != NULL); + + if (self->fd == -1) + return -1; + + return dup (self->fd); +} diff --git a/src/libsysprof-capture/sysprof-capture-writer.h b/src/libsysprof-capture/sysprof-capture-writer.h index 6cbbd5ee..bde8c174 100644 --- a/src/libsysprof-capture/sysprof-capture-writer.h +++ b/src/libsysprof-capture/sysprof-capture-writer.h @@ -244,5 +244,7 @@ SYSPROF_INTERNAL bool _sysprof_capture_writer_set_time_range (SysprofCaptureWriter *self, int64_t start_time, int64_t end_time) SYSPROF_INTERNAL; +SYSPROF_INTERNAL +int _sysprof_capture_writer_dup_fd (SysprofCaptureWriter *self); SYSPROF_END_DECLS