aboutsummaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
authorFabiano Rosas <farosas@suse.de>2024-03-11 20:33:34 -0300
committerPeter Xu <peterx@redhat.com>2024-03-12 15:22:23 -0400
commit4760cedc61328e47bf7f1fabceb9937facfa4cdd (patch)
tree6eef4197a0c83d12afca866005569787b03106f4 /io
parent35ac6831d98e18e2c78c85c93e3a6ca1f1ae3e58 (diff)
io: Introduce qio_channel_file_new_dupfd
Add a new helper function for creating a QIOChannelFile channel with a duplicated file descriptor. This saves the calling code from having to do error checking on the dup() call. Suggested-by: "Daniel P. Berrangé" <berrange@redhat.com> Signed-off-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: "Daniel P. Berrangé" <berrange@redhat.com> Link: https://lore.kernel.org/r/20240311233335.17299-2-farosas@suse.de Signed-off-by: Peter Xu <peterx@redhat.com>
Diffstat (limited to 'io')
-rw-r--r--io/channel-file.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/io/channel-file.c b/io/channel-file.c
index a6ad7770c6..6436cfb6ae 100644
--- a/io/channel-file.c
+++ b/io/channel-file.c
@@ -45,6 +45,18 @@ qio_channel_file_new_fd(int fd)
return ioc;
}
+QIOChannelFile *
+qio_channel_file_new_dupfd(int fd, Error **errp)
+{
+ int newfd = dup(fd);
+
+ if (newfd < 0) {
+ error_setg_errno(errp, errno, "Could not dup FD %d", fd);
+ return NULL;
+ }
+
+ return qio_channel_file_new_fd(newfd);
+}
QIOChannelFile *
qio_channel_file_new_path(const char *path,