changeset 14851:4bcd507e8907

Added o_stream_get_fd().
author Timo Sirainen <tss@iki.fi>
date Sat, 11 Aug 2012 02:53:49 +0300
parents 6008a36cb36c
children 04abd58abf7a
files src/lib-compression/ostream-bzlib.c src/lib-compression/ostream-zlib.c src/lib-fs/ostream-cmp.c src/lib-ssl-iostream/ostream-openssl.c src/lib/ostream-buffer.c src/lib/ostream-file.c src/lib/ostream-private.h src/lib/ostream-rawlog.c src/lib/ostream.c src/lib/ostream.h
diffstat 10 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-compression/ostream-bzlib.c	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib-compression/ostream-bzlib.c	Sat Aug 11 02:53:49 2012 +0300
@@ -217,6 +217,7 @@
 
 	zstream->zs.next_out = zstream->outbuf;
 	zstream->zs.avail_out = sizeof(zstream->outbuf);
-	return o_stream_create(&zstream->ostream, output);
+	return o_stream_create(&zstream->ostream, output,
+			       o_stream_get_fd(output));
 }
 #endif
--- a/src/lib-compression/ostream-zlib.c	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib-compression/ostream-zlib.c	Sat Aug 11 02:53:49 2012 +0300
@@ -310,7 +310,8 @@
 
 	zstream->zs.next_out = zstream->outbuf;
 	zstream->zs.avail_out = sizeof(zstream->outbuf);
-	return o_stream_create(&zstream->ostream, output);
+	return o_stream_create(&zstream->ostream, output,
+			       o_stream_get_fd(output));
 }
 
 struct ostream *o_stream_create_gz(struct ostream *output, int level)
--- a/src/lib-fs/ostream-cmp.c	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib-fs/ostream-cmp.c	Sat Aug 11 02:53:49 2012 +0300
@@ -80,7 +80,8 @@
 	cstream->equals = TRUE;
 	i_stream_ref(input);
 
-	return o_stream_create(&cstream->ostream, output);
+	return o_stream_create(&cstream->ostream, output,
+			       o_stream_get_fd(output));
 }
 
 bool o_stream_cmp_equals(struct ostream *_output)
--- a/src/lib-ssl-iostream/ostream-openssl.c	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib-ssl-iostream/ostream-openssl.c	Sat Aug 11 02:53:49 2012 +0300
@@ -256,5 +256,6 @@
 	o_stream_set_flush_callback(ssl_io->plain_output,
 				    plain_flush_callback, sstream);
 
-	return o_stream_create(&sstream->ostream, NULL);
+	return o_stream_create(&sstream->ostream, NULL,
+			       o_stream_get_fd(ssl_io->plain_output));
 }
--- a/src/lib/ostream-buffer.c	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib/ostream-buffer.c	Sat Aug 11 02:53:49 2012 +0300
@@ -60,7 +60,7 @@
 	bstream->ostream.write_at = o_stream_buffer_write_at;
 
 	bstream->buf = buf;
-	output = o_stream_create(&bstream->ostream, NULL);
+	output = o_stream_create(&bstream->ostream, NULL, -1);
 	o_stream_set_name(output, "(buffer)");
 	return output;
 }
--- a/src/lib/ostream-file.c	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib/ostream-file.c	Sat Aug 11 02:53:49 2012 +0300
@@ -933,7 +933,7 @@
 
 	fstream = o_stream_create_fd_common(fd, autoclose_fd);
 	fstream->ostream.max_buffer_size = max_buffer_size;
-	ostream = o_stream_create(&fstream->ostream, NULL);
+	ostream = o_stream_create(&fstream->ostream, NULL, fd);
 
 	offset = lseek(fd, 0, SEEK_CUR);
 	if (offset >= 0) {
@@ -969,7 +969,7 @@
 	fstream->real_offset = offset;
 	fstream->buffer_offset = offset;
 
-	ostream = o_stream_create(&fstream->ostream, NULL);
+	ostream = o_stream_create(&fstream->ostream, NULL, fd);
 	ostream->offset = offset;
 	return ostream;
 }
--- a/src/lib/ostream-private.h	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib/ostream-private.h	Sat Aug 11 02:53:49 2012 +0300
@@ -32,6 +32,7 @@
 
 	struct ostream *parent; /* for filter streams */
 
+	int fd;
 	stream_flush_callback_t *callback;
 	void *context;
 
@@ -41,7 +42,7 @@
 };
 
 struct ostream *
-o_stream_create(struct ostream_private *_stream, struct ostream *parent)
+o_stream_create(struct ostream_private *_stream, struct ostream *parent, int fd)
 	ATTR_NULL(2);
 
 off_t io_stream_copy(struct ostream *outstream, struct istream *instream,
--- a/src/lib/ostream-rawlog.c	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib/ostream-rawlog.c	Sat Aug 11 02:53:49 2012 +0300
@@ -58,5 +58,5 @@
 	rstream->riostream.autoclose_fd = autoclose_fd;
 	rstream->riostream.write_timestamp = TRUE;
 
-	return o_stream_create(&rstream->ostream, output);
+	return o_stream_create(&rstream->ostream, output, -1);
 }
--- a/src/lib/ostream.c	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib/ostream.c	Sat Aug 11 02:53:49 2012 +0300
@@ -20,6 +20,11 @@
 	return stream->real_stream->iostream.name;
 }
 
+int o_stream_get_fd(struct ostream *stream)
+{
+	return stream->real_stream->fd;
+}
+
 void o_stream_destroy(struct ostream **stream)
 {
 	o_stream_close(*stream);
@@ -459,8 +464,9 @@
 }
 
 struct ostream *
-o_stream_create(struct ostream_private *_stream, struct ostream *parent)
+o_stream_create(struct ostream_private *_stream, struct ostream *parent, int fd)
 {
+	_stream->fd = fd;
 	_stream->ostream.real_stream = _stream;
 	if (parent != NULL) {
 		_stream->parent = parent;
--- a/src/lib/ostream.h	Sat Aug 11 02:16:07 2012 +0300
+++ b/src/lib/ostream.h	Sat Aug 11 02:53:49 2012 +0300
@@ -42,6 +42,9 @@
 /* Get output stream's name. Returns "" if stream has no name. */
 const char *o_stream_get_name(struct ostream *stream);
 
+/* Return file descriptor for stream, or -1 if none is available. */
+int o_stream_get_fd(struct ostream *stream);
+
 /* o_stream_close() + o_stream_unref() */
 void o_stream_destroy(struct ostream **stream);
 /* Reference counting. References start from 1, so calling o_stream_unref()