iostream-temp.c revision b3f4c31f1533e25380f49f77d5bb1251bf43db2a
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen/* Copyright (c) 2013-2014 Dovecot authors, see the included COPYING file */
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen uoff_t dupstream_offset, dupstream_start_offset;
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Siraineno_stream_temp_close(struct iostream_private *stream,
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen struct temp_ostream *tstream = (struct temp_ostream *)stream;
2ed75e0243a9845eb4f92436ff6016906a3189e4Timo Sirainenstatic int o_stream_temp_move_to_fd(struct temp_ostream *tstream)
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen tstream->fd = safe_mkstemp_hostpid(path, 0600, (uid_t)-1, (gid_t)-1);
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen i_error("safe_mkstemp(%s) failed: %m", str_c(path));
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen i_error("unlink(%s) failed: %m", str_c(path));
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen if (write_full(tstream->fd, tstream->buf->data, tstream->buf->used) < 0) {
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Siraineno_stream_temp_fd_sendv(struct temp_ostream *tstream,
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen const struct const_iovec *iov, unsigned int iov_count)
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen unsigned int i;
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen for (i = 0; i < iov_count; i++) {
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen if (write_full(tstream->fd, iov[i].iov_base, iov[i].iov_len) < 0) {
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen tstream->ostream.ostream.stream_errno = errno;
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen tstream->ostream.ostream.offset += iov[i].iov_len;
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Siraineno_stream_temp_sendv(struct ostream_private *stream,
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen const struct const_iovec *iov, unsigned int iov_count)
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen struct temp_ostream *tstream = (struct temp_ostream *)stream;
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen unsigned int i;
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen tstream->flags &= ~IOSTREAM_TEMP_FLAG_TRY_FD_DUP;
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen return o_stream_temp_fd_sendv(tstream, iov, iov_count);
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen for (i = 0; i < iov_count; i++) {
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen if (tstream->buf->used + iov[i].iov_len > IOSTREAM_TEMP_MAX_BUF_SIZE) {
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen /* failed to move to temp fd, just keep it in memory */
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainen buffer_append(tstream->buf, iov[i].iov_base, iov[i].iov_len);
5c2d695acf9f95ae0dcdda89c4d2391ceda4d672Timo Sirainenstatic int o_stream_temp_dup_cancel(struct temp_ostream *tstream)
return ret;
int ret;
if (ret < 0)
return output;
int fd;
return input;