32
32
bool autoclose_fd);
33
33
struct istream *i_stream_create_from_data(const void *data, size_t size);
34
34
struct istream *i_stream_create_limit(struct istream *input, uoff_t v_size);
35
struct istream *i_stream_create_range(struct istream *input,
36
uoff_t v_offset, uoff_t v_size);
37
struct istream *i_stream_create_error(int stream_errno);
39
i_stream_create_error_str(int stream_errno, const char *fmt, ...)
36
42
/* Set name (e.g. path) for input stream. */
37
43
void i_stream_set_name(struct istream *stream, const char *name);
40
46
Returns "" if stream has no name. */
41
47
const char *i_stream_get_name(struct istream *stream);
43
/* i_stream_close() + i_stream_unref() */
49
/* Close this stream (but not its parents) and unreference it. */
44
50
void i_stream_destroy(struct istream **stream);
46
52
/* Reference counting. References start from 1, so calling i_stream_unref()
49
55
/* Unreferences the stream and sets stream pointer to NULL. */
50
56
void i_stream_unref(struct istream **stream);
51
57
/* Call the given callback function when stream is destroyed. */
52
void i_stream_set_destroy_callback(struct istream *stream,
53
istream_callback_t *callback, void *context);
54
#define i_stream_set_destroy_callback(stream, callback, context) \
55
CONTEXT_CALLBACK(i_stream_set_destroy_callback, istream_callback_t, \
56
callback, context, stream)
58
void i_stream_add_destroy_callback(struct istream *stream,
59
istream_callback_t *callback, void *context)
61
#define i_stream_add_destroy_callback(stream, callback, context) \
62
i_stream_add_destroy_callback(stream + \
63
CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
64
(istream_callback_t *)callback, context)
57
65
/* Remove the destroy callback. */
58
void i_stream_unset_destroy_callback(struct istream *stream);
66
void i_stream_remove_destroy_callback(struct istream *stream,
60
69
/* Return file descriptor for stream, or -1 if none is available. */
61
70
int i_stream_get_fd(struct istream *stream);
71
/* Returns error string for the last error. */
72
const char *i_stream_get_error(struct istream *stream);
63
/* Mark the stream closed. Any reads after this will return -1. The data
64
already read can still be used. */
74
/* Mark the stream and all of its parent streams closed. Any reads after this
75
will return -1. The data already read can still be used. */
65
76
void i_stream_close(struct istream *stream);
66
77
/* Sync the stream with the underlying backend, ie. if a file has been
67
78
modified, flush any cached data. */
94
105
stream's implementation is slow in seeking backwards, it can use this hint
95
106
to cache some of the data in memory. */
96
107
void i_stream_seek_mark(struct istream *stream, uoff_t v_offset);
97
/* Returns struct stat, or NULL if error. As the underlying stream may not be
108
/* Returns 0 if ok, -1 if error. As the underlying stream may not be
98
109
a file, only some of the fields might be set, others would be zero.
99
110
st_size is always set, and if it's not known, it's -1.
101
112
If exact=FALSE, the stream may not return exactly correct values, but the
102
113
returned values can be compared to see if anything had changed (eg. in
103
114
compressed stream st_size could be compressed size) */
104
const struct stat *i_stream_stat(struct istream *stream, bool exact);
115
int i_stream_stat(struct istream *stream, bool exact, const struct stat **st_r);
105
116
/* Similar to i_stream_stat() call. Returns 1 if size was successfully
106
117
set, 0 if size is unknown, -1 if error. */
107
118
int i_stream_get_size(struct istream *stream, bool exact, uoff_t *size_r);
118
129
if the last line should be returned if it doesn't end with LF. */
119
130
char *i_stream_next_line(struct istream *stream);
120
131
/* Like i_stream_next_line(), but reads for more data if needed. Returns NULL
121
if more data is needed or error occurred. */
132
if more data is needed or error occurred. If the input buffer gets full,
133
stream_errno is set to ENOBUFS. */
122
134
char *i_stream_read_next_line(struct istream *stream);
135
/* Returns TRUE if the last line read with i_stream_next_line() ended with
136
CRLF (instead of LF). */
137
bool i_stream_last_line_crlf(struct istream *stream);
124
139
/* Returns pointer to beginning of read data, or NULL if there's no data
126
141
const unsigned char *
127
142
i_stream_get_data(const struct istream *stream, size_t *size_r);
143
size_t i_stream_get_data_size(const struct istream *stream);
128
144
/* Like i_stream_get_data(), but returns non-const data. This only works with
129
145
buffered streams (currently only file), others return NULL. */
130
146
unsigned char *i_stream_get_modifiable_data(const struct istream *stream,