1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
1 |
#ifndef ISTREAM_H
|
2 |
#define ISTREAM_H
|
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
3 |
|
1.10.2
by Martin Pitt
Import upstream version 1.0.beta9 |
4 |
/* Note that some systems (Solaris) may use a macro to redefine struct stat */
|
5 |
#include <sys/stat.h> |
|
6 |
||
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
7 |
struct istream { |
1.1.1
by Jaldhar H. Vyas
Import upstream version 1.0.alpha4 |
8 |
uoff_t v_offset; |
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
9 |
|
10 |
int stream_errno; |
|
11 |
unsigned int mmaped:1; /* be careful when copying data */ |
|
1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
12 |
unsigned int blocking:1; /* read() shouldn't return 0 */ |
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
13 |
unsigned int closed:1; |
1.12.1
by Joel Johnson
Import upstream version 1.2.1 |
14 |
unsigned int readable_fd:1; /* fd can be read directly if necessary |
15 |
(for sendfile()) */
|
|
1.1.1
by Jaldhar H. Vyas
Import upstream version 1.0.alpha4 |
16 |
unsigned int seekable:1; /* we can seek() backwards */ |
17 |
unsigned int eof:1; /* read() has reached to end of file |
|
18 |
(but may still be data available in buffer) */
|
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
19 |
|
1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
20 |
struct istream_private *real_stream; |
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
21 |
};
|
22 |
||
1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
23 |
typedef void istream_callback_t(void *context); |
24 |
||
25 |
struct istream *i_stream_create_fd(int fd, size_t max_buffer_size, |
|
26 |
bool autoclose_fd); |
|
1.13.8
by Marco Nenciarini
Import upstream version 2.0.11 |
27 |
/* Open the given path only when something is actually tried to be read from
|
28 |
the stream. */
|
|
29 |
struct istream *i_stream_create_file(const char *path, size_t max_buffer_size); |
|
1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
30 |
struct istream *i_stream_create_mmap(int fd, size_t block_size, |
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
31 |
uoff_t start_offset, uoff_t v_size, |
1.6.1
by Martin Pitt
Import upstream version 1.0.beta3 |
32 |
bool autoclose_fd); |
1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
33 |
struct istream *i_stream_create_from_data(const void *data, size_t size); |
34 |
struct istream *i_stream_create_limit(struct istream *input, uoff_t v_size); |
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
35 |
|
1.13.8
by Marco Nenciarini
Import upstream version 2.0.11 |
36 |
/* Set name (e.g. path) for input stream. */
|
37 |
void i_stream_set_name(struct istream *stream, const char *name); |
|
38 |
/* Get input stream's name. If stream itself doesn't have a name,
|
|
39 |
it looks up further into stream's parents until one of them has a name.
|
|
40 |
Returns "" if stream has no name. */
|
|
41 |
const char *i_stream_get_name(struct istream *stream); |
|
42 |
||
1.10.2
by Martin Pitt
Import upstream version 1.0.beta9 |
43 |
/* i_stream_close() + i_stream_unref() */
|
44 |
void i_stream_destroy(struct istream **stream); |
|
45 |
||
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
46 |
/* Reference counting. References start from 1, so calling i_stream_unref()
|
47 |
destroys the stream if i_stream_ref() is never used. */
|
|
48 |
void i_stream_ref(struct istream *stream); |
|
1.6.1
by Martin Pitt
Import upstream version 1.0.beta3 |
49 |
/* Unreferences the stream and sets stream pointer to NULL. */
|
50 |
void i_stream_unref(struct istream **stream); |
|
1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
51 |
/* 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)
|
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
57 |
|
58 |
/* Return file descriptor for stream, or -1 if none is available. */
|
|
59 |
int i_stream_get_fd(struct istream *stream); |
|
60 |
||
61 |
/* Mark the stream closed. Any reads after this will return -1. The data
|
|
62 |
already read can still be used. */
|
|
63 |
void i_stream_close(struct istream *stream); |
|
1.1.1
by Jaldhar H. Vyas
Import upstream version 1.0.alpha4 |
64 |
/* Sync the stream with the underlying backend, ie. if a file has been
|
65 |
modified, flush any cached data. */
|
|
66 |
void i_stream_sync(struct istream *stream); |
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
67 |
|
1.11.4
by Fabio Tranchitella
Import upstream version 1.2.4 |
68 |
/* Change the initial size for stream's input buffer. This basically just
|
69 |
grows the read buffer size from the default. This function has no effect
|
|
70 |
unless it's called before reading anything. */
|
|
71 |
void i_stream_set_init_buffer_size(struct istream *stream, size_t size); |
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
72 |
/* Change the maximum size for stream's input buffer to grow. Useful only
|
73 |
for buffered streams (currently only file). */
|
|
74 |
void i_stream_set_max_buffer_size(struct istream *stream, size_t max_size); |
|
1.13.8
by Marco Nenciarini
Import upstream version 2.0.11 |
75 |
/* Returns the current max. buffer size. */
|
76 |
size_t i_stream_get_max_buffer_size(struct istream *stream); |
|
1.10.17
by Mathias Gug
Import upstream version 1.1.11 |
77 |
/* Enable/disable i_stream[_read]_next_line() returning the last line if it
|
78 |
doesn't end with LF. */
|
|
79 |
void i_stream_set_return_partial_line(struct istream *stream, bool set); |
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
80 |
|
81 |
/* Returns number of bytes read if read was ok, -1 if EOF or error, -2 if the
|
|
82 |
input buffer is full. */
|
|
83 |
ssize_t i_stream_read(struct istream *stream); |
|
84 |
/* Skip forward a number of bytes. Never fails, the next read tells if it
|
|
85 |
was successful. */
|
|
86 |
void i_stream_skip(struct istream *stream, uoff_t count); |
|
87 |
/* Seek to specified position from beginning of file. Never fails, the next
|
|
88 |
read tells if it was successful. This works only for files. */
|
|
89 |
void i_stream_seek(struct istream *stream, uoff_t v_offset); |
|
1.1.1
by Jaldhar H. Vyas
Import upstream version 1.0.alpha4 |
90 |
/* Like i_stream_seek(), but also giving a hint that after reading some data
|
91 |
we could be seeking back to this mark or somewhere after it. If input
|
|
92 |
stream's implementation is slow in seeking backwards, it can use this hint
|
|
93 |
to cache some of the data in memory. */
|
|
94 |
void i_stream_seek_mark(struct istream *stream, uoff_t v_offset); |
|
95 |
/* Returns struct stat, or NULL if error. As the underlying stream may not be
|
|
96 |
a file, only some of the fields might be set, others would be zero.
|
|
97 |
st_size is always set, and if it's not known, it's -1.
|
|
98 |
||
99 |
If exact=FALSE, the stream may not return exactly correct values, but the
|
|
100 |
returned values can be compared to see if anything had changed (eg. in
|
|
101 |
compressed stream st_size could be compressed size) */
|
|
1.6.1
by Martin Pitt
Import upstream version 1.0.beta3 |
102 |
const struct stat *i_stream_stat(struct istream *stream, bool exact); |
1.13.8
by Marco Nenciarini
Import upstream version 2.0.11 |
103 |
/* Similar to i_stream_stat() call. Returns 1 if size was successfully
|
104 |
set, 0 if size is unknown, -1 if error. */
|
|
105 |
int i_stream_get_size(struct istream *stream, bool exact, uoff_t *size_r); |
|
1.1.1
by Jaldhar H. Vyas
Import upstream version 1.0.alpha4 |
106 |
/* Returns TRUE if there are any bytes left to be read or in buffer. */
|
1.12.1
by Joel Johnson
Import upstream version 1.2.1 |
107 |
bool i_stream_have_bytes_left(const struct istream *stream) ATTR_PURE; |
1.13.8
by Marco Nenciarini
Import upstream version 2.0.11 |
108 |
/* Returns TRUE if there are no bytes buffered and read() returns EOF. */
|
109 |
bool i_stream_is_eof(struct istream *stream); |
|
110 |
/* Returns the absolute offset of the stream. This is the stream's current
|
|
111 |
v_offset + the parent's absolute offset when the stream was created. */
|
|
112 |
uoff_t i_stream_get_absolute_offset(struct istream *stream); |
|
1.1.1
by Jaldhar H. Vyas
Import upstream version 1.0.alpha4 |
113 |
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
114 |
/* Gets the next line from stream and returns it, or NULL if more data is
|
1.10.17
by Mathias Gug
Import upstream version 1.1.11 |
115 |
needed to make a full line. i_stream_set_return_partial_line() specifies
|
116 |
if the last line should be returned if it doesn't end with LF. */
|
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
117 |
char *i_stream_next_line(struct istream *stream); |
118 |
/* Like i_stream_next_line(), but reads for more data if needed. Returns NULL
|
|
1.1.1
by Jaldhar H. Vyas
Import upstream version 1.0.alpha4 |
119 |
if more data is needed or error occurred. */
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
120 |
char *i_stream_read_next_line(struct istream *stream); |
1.1.1
by Jaldhar H. Vyas
Import upstream version 1.0.alpha4 |
121 |
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
122 |
/* Returns pointer to beginning of read data, or NULL if there's no data
|
123 |
buffered. */
|
|
1.12.1
by Joel Johnson
Import upstream version 1.2.1 |
124 |
const unsigned char * |
125 |
i_stream_get_data(const struct istream *stream, size_t *size_r); |
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
126 |
/* Like i_stream_get_data(), but returns non-const data. This only works with
|
127 |
buffered streams (currently only file), others return NULL. */
|
|
1.12.1
by Joel Johnson
Import upstream version 1.2.1 |
128 |
unsigned char *i_stream_get_modifiable_data(const struct istream *stream, |
1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
129 |
size_t *size_r); |
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
130 |
/* Like i_stream_get_data(), but read more when needed. Returns 1 if more
|
1.12.1
by Joel Johnson
Import upstream version 1.2.1 |
131 |
than threshold bytes are available, 0 if as much or less, -1 if error or
|
132 |
EOF with no bytes read that weren't already in buffer, or -2 if stream's
|
|
133 |
input buffer is full. */
|
|
1.10.15
by Matthias Klose
Import upstream version 1.1.2 |
134 |
int i_stream_read_data(struct istream *stream, const unsigned char **data_r, |
135 |
size_t *size_r, size_t threshold); |
|
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
136 |
|
1.12.1
by Joel Johnson
Import upstream version 1.2.1 |
137 |
/* Append external data to input stream. Returns TRUE if successful, FALSE if
|
138 |
there is not enough space in the stream. */
|
|
139 |
bool i_stream_add_data(struct istream *stream, const unsigned char *data, |
|
140 |
size_t size); |
|
141 |
||
1
by Jaldhar H. Vyas
Import upstream version 0.99.13 |
142 |
#endif
|