]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add i_stream_copy_fd()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 8 Mar 2021 14:33:33 +0000 (16:33 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 17 May 2021 12:39:14 +0000 (12:39 +0000)
src/lib/istream.c
src/lib/istream.h

index 32ee3cee986539a91f15f639e0ba3a45a36a07fb..93c57034701b5d698629dcf3efd788ac3053032b 100644 (file)
@@ -88,6 +88,16 @@ int i_stream_get_fd(struct istream *stream)
        return _stream->fd;
 }
 
+void i_stream_copy_fd(struct istream *dest, struct istream *source)
+{
+       int fd = i_stream_get_fd(source);
+
+       i_assert(fd != -1);
+       i_assert(dest->real_stream->fd == -1);
+       dest->real_stream->fd = fd;
+       dest->readable_fd = source->readable_fd;
+}
+
 const char *i_stream_get_error(struct istream *stream)
 {
        struct istream *s;
index 2ea9601463361089431ec72dc49a105da4c1f4e0..ed3d793cd095c01302a9b1cbc7b4080bf8f119cf 100644 (file)
@@ -97,6 +97,10 @@ void i_stream_remove_destroy_callback(struct istream *stream,
 
 /* Return file descriptor for stream, or -1 if none is available. */
 int i_stream_get_fd(struct istream *stream);
+/* Copy the file descriptor from source istream to destination istream.
+   The readable_fd is preserved. Assert-crashes if source doesn't have a
+   file descriptor. */
+void i_stream_copy_fd(struct istream *dest, struct istream *source);
 /* Returns error string for the last error. It also returns "EOF" in case there
    is no error, but eof is set. Otherwise it returns "<no error>". */
 const char *i_stream_get_error(struct istream *stream);