istream.h revision cd56a23e21f1df3f79648cf07e2f4385e2fadebb
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen unsigned int mmaped:1; /* be careful when copying data */
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen unsigned int seekable:1; /* we can seek() backwards */
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen unsigned int eof:1; /* read() has reached to end of file
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen (but may still be data available in buffer) */
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainenstruct istream *i_stream_create_file(int fd, pool_t pool,
3ddbbe03fe74b3ee7b1dff4e08ec706d7880d052Timo Sirainenstruct istream *i_stream_create_mmap(int fd, pool_t pool, size_t block_size,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenstruct istream *i_stream_create_from_data(pool_t pool, const void *data,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenstruct istream *i_stream_create_limit(pool_t pool, struct istream *input,
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen/* i_stream_close() + i_stream_unref() */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid i_stream_destroy(struct istream **stream);
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen/* Reference counting. References start from 1, so calling i_stream_unref()
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen destroys the stream if i_stream_ref() is never used. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Unreferences the stream and sets stream pointer to NULL. */
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen/* Return file descriptor for stream, or -1 if none is available. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Mark the stream closed. Any reads after this will return -1. The data
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen already read can still be used. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Sync the stream with the underlying backend, ie. if a file has been
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen modified, flush any cached data. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Change the maximum size for stream's input buffer to grow. Useful only
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen for buffered streams (currently only file). */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid i_stream_set_max_buffer_size(struct istream *stream, size_t max_size);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Returns number of bytes read if read was ok, -1 if EOF or error, -2 if the
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen input buffer is full. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Skip forward a number of bytes. Never fails, the next read tells if it
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen was successful. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid i_stream_skip(struct istream *stream, uoff_t count);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Seek to specified position from beginning of file. Never fails, the next
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen read tells if it was successful. This works only for files. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid i_stream_seek(struct istream *stream, uoff_t v_offset);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Like i_stream_seek(), but also giving a hint that after reading some data
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen we could be seeking back to this mark or somewhere after it. If input
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen stream's implementation is slow in seeking backwards, it can use this hint
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen to cache some of the data in memory. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenvoid i_stream_seek_mark(struct istream *stream, uoff_t v_offset);
f1e9611e93dcb3b745c1904029084fa81644e1b3Timo Sirainen/* Returns struct stat, or NULL if error. As the underlying stream may not be
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen a file, only some of the fields might be set, others would be zero.
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen st_size is always set, and if it's not known, it's -1.
4c07b08af30e1065f7022980b60474f229d8cadfTimo Sirainen If exact=FALSE, the stream may not return exactly correct values, but the
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen returned values can be compared to see if anything had changed (eg. in
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen compressed stream st_size could be compressed size) */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenconst struct stat *i_stream_stat(struct istream *stream, bool exact);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Returns TRUE if there are any bytes left to be read or in buffer. */
baf1148108b7d9739626b47cc57298c36929586aTimo Sirainenbool i_stream_have_bytes_left(struct istream *stream);
4c07b08af30e1065f7022980b60474f229d8cadfTimo Sirainen/* Gets the next line from stream and returns it, or NULL if more data is
baf1148108b7d9739626b47cc57298c36929586aTimo Sirainen needed to make a full line. Note that if the stream ends with LF not being
baf1148108b7d9739626b47cc57298c36929586aTimo Sirainen the last character, this function doesn't return the last line. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenchar *i_stream_next_line(struct istream *stream);
4c07b08af30e1065f7022980b60474f229d8cadfTimo Sirainen/* Like i_stream_next_line(), but reads for more data if needed. Returns NULL
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if more data is needed or error occurred. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenchar *i_stream_read_next_line(struct istream *stream);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Returns pointer to beginning of read data, or NULL if there's no data
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenconst unsigned char *i_stream_get_data(struct istream *stream, size_t *size);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Like i_stream_get_data(), but returns non-const data. This only works with
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen buffered streams (currently only file), others return NULL. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenunsigned char *i_stream_get_modifyable_data(struct istream *stream,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Like i_stream_get_data(), but read more when needed. Returns 1 if more
6389aeec8c26b585e583c364b48ad12adf741898Timo Sirainen than threshold bytes are available, 0 if less, -1 if error or EOF with no
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen bytes read that weren't already in buffer, or -2 if stream's input buffer
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenint i_stream_read_data(struct istream *stream, const unsigned char **data,