istream-file.c revision 14175321ddb88619015866978c05a27786ca4814
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen/* Copyright (c) 2002-2007 Dovecot authors, see the included COPYING file */
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen/* @UNSAFE: whole file */
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenstatic void i_stream_file_close(struct iostream_private *stream)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen struct file_istream *fstream = (struct file_istream *)stream;
acc8c0647873b1c847bfa362ddefd0d219d0aa91Timo Sirainen struct istream_private *_stream = (struct istream_private *)stream;
acc8c0647873b1c847bfa362ddefd0d219d0aa91Timo Sirainen if (fstream->autoclose_fd && _stream->fd != -1) {
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenstatic void i_stream_file_destroy(struct iostream_private *stream)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen struct istream_private *_stream = (struct istream_private *)stream;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenstatic ssize_t i_stream_file_read(struct istream_private *stream)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen struct file_istream *fstream = (struct file_istream *) stream;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen if (!i_stream_get_buffer_space(stream, 1, &size))
9446c7a5d400cba60d097c528bd08312552438e3Timo Sirainen ret = pread(stream->fd, stream->w_buffer + stream->pos,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen ret = read(stream->fd, stream->w_buffer + stream->pos,
ad3a1b8f8e2a5596afb1b099a69ae6f688887eecTimo Sirainen } while (ret < 0 && errno == EINTR && stream->istream.blocking);
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenstatic void i_stream_file_seek(struct istream_private *stream, uoff_t v_offset,
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen struct file_istream *fstream = (struct file_istream *) stream;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen fstream->skip_left += v_offset - stream->istream.v_offset;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenstatic void i_stream_file_sync(struct istream_private *stream)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen /* can't do anything or data would be lost */
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainenstatic const struct stat *
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Siraineni_stream_file_stat(struct istream_private *stream, bool exact ATTR_UNUSED)
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen struct file_istream *fstream = (struct file_istream *) stream;
b494ffed8ded8d170d9ace3dc607b1d278048241Timo Sirainen if (fstat(fstream->istream.fd, &fstream->istream.statbuf) < 0) {
bool autoclose_fd)