diff options
author | Fabiano Rosas <farosas@suse.de> | 2024-03-11 20:33:34 -0300 |
---|---|---|
committer | Peter Xu <peterx@redhat.com> | 2024-03-12 15:22:23 -0400 |
commit | 4760cedc61328e47bf7f1fabceb9937facfa4cdd (patch) | |
tree | 6eef4197a0c83d12afca866005569787b03106f4 /include/io/channel-file.h | |
parent | 35ac6831d98e18e2c78c85c93e3a6ca1f1ae3e58 (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 'include/io/channel-file.h')
-rw-r--r-- | include/io/channel-file.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/io/channel-file.h b/include/io/channel-file.h index 50e8eb1138..d373a4e44d 100644 --- a/include/io/channel-file.h +++ b/include/io/channel-file.h @@ -69,6 +69,24 @@ QIOChannelFile * qio_channel_file_new_fd(int fd); /** + * qio_channel_file_new_dupfd: + * @fd: the file descriptor + * @errp: pointer to initialized error object + * + * Create a new IO channel object for a file represented by the @fd + * parameter. Like qio_channel_file_new_fd(), but the @fd is first + * duplicated with dup(). + * + * The channel will own the duplicated file descriptor and will take + * responsibility for closing it, the original FD is owned by the + * caller. + * + * Returns: the new channel object + */ +QIOChannelFile * +qio_channel_file_new_dupfd(int fd, Error **errp); + +/** * qio_channel_file_new_path: * @path: the file path * @flags: the open flags (O_RDONLY|O_WRONLY|O_RDWR, etc) |