]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Added ostream-null
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 12 Apr 2016 17:00:51 +0000 (20:00 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 12 Apr 2016 17:01:13 +0000 (20:01 +0300)
src/lib/Makefile.am
src/lib/ostream-null.c [new file with mode: 0644]
src/lib/ostream-null.h [new file with mode: 0644]

index 712ec856e77fc19b2f5920fd448ec23cd46706f5..d5705e90587e97121c9c2ebf1c9c1947ca527db1 100644 (file)
@@ -112,6 +112,7 @@ liblib_la_SOURCES = \
        ostream-failure-at.c \
        ostream-file.c \
        ostream-hash.c \
+       ostream-null.c \
        ostream-rawlog.c \
        primes.c \
        printf-format-fix.c \
@@ -244,6 +245,7 @@ headers = \
        ostream-failure-at.h \
        ostream-hash.h \
        ostream-private.h \
+       ostream-null.h \
        ostream-rawlog.h \
        primes.h \
        printf-format-fix.h \
diff --git a/src/lib/ostream-null.c b/src/lib/ostream-null.c
new file mode 100644 (file)
index 0000000..7c00284
--- /dev/null
@@ -0,0 +1,32 @@
+/* Copyright (c) 2016 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "ostream-private.h"
+#include "ostream-null.h"
+
+static ssize_t
+o_stream_null_sendv(struct ostream_private *stream,
+                   const struct const_iovec *iov, unsigned int iov_count)
+{
+       unsigned int i;
+       size_t ret = 0;
+
+       for (i = 0; i < iov_count; i++)
+               ret += iov[i].iov_len;
+       stream->ostream.offset += ret;
+       return ret;
+}
+
+struct ostream *o_stream_create_null(void)
+{
+       struct ostream_private *stream;
+       struct ostream *output;
+
+       stream = i_new(struct ostream_private, 1);
+       stream->sendv = o_stream_null_sendv;
+
+       output = o_stream_create(stream, NULL, -1);
+       o_stream_set_no_error_handling(output, TRUE);
+       o_stream_set_name(output, "(/dev/null)");
+       return output;
+}
diff --git a/src/lib/ostream-null.h b/src/lib/ostream-null.h
new file mode 100644 (file)
index 0000000..7c83c80
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef OSTREAM_NULL_H
+#define OSTREAM_NULL_H
+
+/* Create an output stream that ignores all the writes. */
+struct ostream *o_stream_create_null(void);
+
+#endif