From: Timo Sirainen Date: Tue, 12 Apr 2016 17:00:51 +0000 (+0300) Subject: lib: Added ostream-null X-Git-Tag: 2.2.24~68 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d1eec04fac1f40f4d8f4c84f7f90ef6944495418;p=thirdparty%2Fdovecot%2Fcore.git lib: Added ostream-null --- diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 712ec856e7..d5705e9058 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -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 index 0000000000..7c00284718 --- /dev/null +++ b/src/lib/ostream-null.c @@ -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 index 0000000000..7c83c801f3 --- /dev/null +++ b/src/lib/ostream-null.h @@ -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