bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#include "lib.h"
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#include "ostream-private.h"
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen#include "ostream-null.h"
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainenstatic ssize_t
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Siraineno_stream_null_sendv(struct ostream_private *stream,
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen const struct const_iovec *iov, unsigned int iov_count)
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen{
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen unsigned int i;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen size_t ret = 0;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen for (i = 0; i < iov_count; i++)
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen ret += iov[i].iov_len;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen stream->ostream.offset += ret;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen return ret;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen}
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainenstruct ostream *o_stream_create_null(void)
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen{
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct ostream_private *stream;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen struct ostream *output;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen stream = i_new(struct ostream_private, 1);
8b2cf1c1bd8ddcea0525b62fd35ba76e136828a1Timo Sirainen stream->ostream.blocking = TRUE;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen stream->sendv = o_stream_null_sendv;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen output = o_stream_create(stream, NULL, -1);
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen o_stream_set_no_error_handling(output, TRUE);
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen o_stream_set_name(output, "(/dev/null)");
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen return output;
d1eec04fac1f40f4d8f4c84f7f90ef6944495418Timo Sirainen}