istream.h revision 4c096615cb86a826fda377b87df22c579bfe5525
#ifndef ISTREAM_H
#define ISTREAM_H
/* Note that some systems (Solaris) may use a macro to redefine struct stat */
struct istream {
int stream_errno;
unsigned int closed:1;
(for sendfile()) */
(but may still be data available in buffer) */
struct istream_private *real_stream;
};
typedef void istream_callback_t(void *context);
bool autoclose_fd);
/* Open the given path only when something is actually tried to be read from
the stream. */
bool autoclose_fd);
struct istream *
/* Set name (e.g. path) for input stream. */
/* Get input stream's name. If stream itself doesn't have a name,
it looks up further into stream's parents until one of them has a name.
Returns "" if stream has no name. */
/* Close this stream (but not its parents) and unreference it. */
/* Reference counting. References start from 1, so calling i_stream_unref()
destroys the stream if i_stream_ref() is never used. */
/* Unreferences the stream and sets stream pointer to NULL. */
/* Call the given callback function when stream is destroyed. */
ATTR_NULL(3);
/* Remove the destroy callback. */
void (*callback)());
/* Return file descriptor for stream, or -1 if none is available. */
/* Returns error string for the last error. */
/* Mark the stream and all of its parent streams closed. Any reads after this
will return -1. The data already read can still be used. */
/* Sync the stream with the underlying backend, ie. if a file has been
modified, flush any cached data. */
/* Change the initial size for stream's input buffer. This basically just
grows the read buffer size from the default. This function has no effect
unless it's called before reading anything. */
/* Change the maximum size for stream's input buffer to grow. Useful only
for buffered streams (currently only file). */
/* Returns the current max. buffer size. */
doesn't end with LF. */
/* Returns number of bytes read if read was ok, -1 if EOF or error, -2 if the
input buffer is full. */
/* Skip forward a number of bytes. Never fails, the next read tells if it
was successful. */
/* Seek to specified position from beginning of file. Never fails, the next
read tells if it was successful. This works only for files. */
/* Like i_stream_seek(), but also giving a hint that after reading some data
we could be seeking back to this mark or somewhere after it. If input
stream's implementation is slow in seeking backwards, it can use this hint
to cache some of the data in memory. */
/* Returns 0 if ok, -1 if error. As the underlying stream may not be
a file, only some of the fields might be set, others would be zero.
st_size is always set, and if it's not known, it's -1.
If exact=FALSE, the stream may not return exactly correct values, but the
returned values can be compared to see if anything had changed (eg. in
compressed stream st_size could be compressed size) */
/* Similar to i_stream_stat() call. Returns 1 if size was successfully
set, 0 if size is unknown, -1 if error. */
/* Returns TRUE if there are any bytes left to be read or in buffer. */
/* Returns TRUE if there are no bytes buffered and read() returns EOF. */
/* Returns the absolute offset of the stream. This is the stream's current
v_offset + the parent's absolute offset when the stream was created. */
/* Gets the next line from stream and returns it, or NULL if more data is
needed to make a full line. i_stream_set_return_partial_line() specifies
if the last line should be returned if it doesn't end with LF. */
/* Like i_stream_next_line(), but reads for more data if needed. Returns NULL
if more data is needed or error occurred. If the input buffer gets full,
stream_errno is set to ENOBUFS. */
/* Returns TRUE if the last line read with i_stream_next_line() ended with
CRLF (instead of LF). */
/* Returns pointer to beginning of read data, or NULL if there's no data
buffered. */
const unsigned char *
/* Like i_stream_get_data(), but returns non-const data. This only works with
buffered streams (currently only file), others return NULL. */
/* Like i_stream_get_data(), but read more when needed. Returns 1 if more
than threshold bytes are available, 0 if as much or less, -1 if error or
EOF with no bytes read that weren't already in buffer, or -2 if stream's
input buffer is full. */
/* Append external data to input stream. Returns TRUE if successful, FALSE if
there is not enough space in the stream. */
/* If there are any I/O loop items associated with the stream, move all of
them to current_ioloop. */
#endif