From: Timo Sirainen Date: Mon, 8 Mar 2021 14:33:33 +0000 (+0200) Subject: lib: Add i_stream_copy_fd() X-Git-Tag: 2.3.16~142 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8a9ccc5aa5773e60021482c954e3779f33f2be2;p=thirdparty%2Fdovecot%2Fcore.git lib: Add i_stream_copy_fd() --- diff --git a/src/lib/istream.c b/src/lib/istream.c index 32ee3cee98..93c5703470 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -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; diff --git a/src/lib/istream.h b/src/lib/istream.h index 2ea9601463..ed3d793cd0 100644 --- a/src/lib/istream.h +++ b/src/lib/istream.h @@ -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 "". */ const char *i_stream_get_error(struct istream *stream);