istream.h revision 411d6baa37f31d90730e90c4a28c43e1974bbe58
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int mmaped:1; /* be careful when copying data */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int seekable:1; /* we can seek() backwards */
c99fe55d4535d839a6ad0735c4719e076a1adb2cTimo Sirainen unsigned int eof:1; /* read() has reached to end of file
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen (but may still be data available in buffer) */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct istream *i_stream_create_file(int fd, pool_t pool,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct istream *i_stream_create_mmap(int fd, pool_t pool, size_t block_size,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct istream *i_stream_create_from_data(pool_t pool, const void *data,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct istream *i_stream_create_limit(pool_t pool, struct istream *input,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Reference counting. References start from 1, so calling i_stream_unref()
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen destroys the stream if i_stream_ref() is never used. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Return file descriptor for stream, or -1 if none is available. */
17fe695b985e9d6e9dc39c05b24e6b3c3b7e1ba1Timo Sirainen/* Mark the stream closed. Any reads after this will return -1. The data
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen already read can still be used. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Change the maximum size for stream's input buffer to grow. Useful only
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for buffered streams (currently only file). */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid i_stream_set_max_buffer_size(struct istream *stream, size_t max_size);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Returns number of bytes read if read was ok, -1 if EOF or error, -2 if the
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen input buffer is full. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Skip forward a number of bytes. Never fails, the next read tells if it
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen was successful. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid i_stream_skip(struct istream *stream, uoff_t count);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Seek to specified position from beginning of file. Never fails, the next
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen read tells if it was successful. This works only for files. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid i_stream_seek(struct istream *stream, uoff_t v_offset);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Returns size of the stream, or (uoff_t)-1 if unknown */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenuoff_t i_stream_get_size(struct istream *stream);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Returns TRUE if there are any bytes left to be read or in buffer. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenint i_stream_have_bytes_left(struct istream *stream);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Gets the next line from stream and returns it, or NULL if more data is
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen needed to make a full line. NOTE: modifies the data in buffer for the \0,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen so it works only with buffered streams (currently only file). */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenchar *i_stream_next_line(struct istream *stream);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Like i_stream_next_line(), but reads for more data if needed. Returns NULL
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if more data is needed or error occured. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenchar *i_stream_read_next_line(struct istream *stream);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Returns pointer to beginning of read data, or NULL if there's no data
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenconst unsigned char *i_stream_get_data(struct istream *stream, size_t *size);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Like i_stream_get_data(), but returns non-const data. This only works with
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen buffered streams (currently only file), others return NULL. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenunsigned char *i_stream_get_modifyable_data(struct istream *stream,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Like i_stream_get_data(), but read more when needed. Returns 1 if more
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen than threshold bytes are available, 0 if less, -1 if error or EOF with no
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen bytes read that weren't already in buffer, or -2 if stream's input buffer
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainenint i_stream_read_data(struct istream *stream, const unsigned char **data,