str_hash, (hash_cmp_callback_t *)strcmp);
input = i_stream_create_file(pw->fd, default_pool, 4096, FALSE);
- for (;;) {
- line = i_stream_next_line(input);
- if (line == NULL) {
- if (i_stream_read(input) <= 0)
- break;
- continue;
- }
-
+ while ((line = i_stream_read_next_line(input)) != NULL) {
if (*line == '\0' || *line == ':')
continue; /* no username */
linenum = 0;
input = i_stream_create_file(fd, default_pool, 2048, TRUE);
- for (;;) {
- line = i_stream_next_line(input);
- if (line == NULL) {
- if (i_stream_read(input) <= 0)
- break;
- continue;
- }
+ while ((line = i_stream_read_next_line(input)) != NULL) {
linenum++;
/* @UNSAFE: line is modified */
return ret_buf;
}
+char *i_stream_read_next_line(struct istream *stream)
+{
+ char *line;
+
+ line = i_stream_next_line(stream);
+ if (line != NULL)
+ return line;
+
+ if (i_stream_read(stream) > 0)
+ line = i_stream_next_line(stream);
+ return line;
+}
+
const unsigned char *i_stream_get_data(struct istream *stream, size_t *size)
{
struct _istream *_stream = stream->real_stream;
/* Seek to specified position from beginning of file. Never fails, the next
read tells if it was successful. This works only for files. */
void i_stream_seek(struct istream *stream, uoff_t v_offset);
-/* Reads the next line from stream and returns it, or NULL if more data is
+/* Gets the next line from stream and returns it, or NULL if more data is
needed to make a full line. NOTE: modifies the data in buffer for the \0,
so it works only with buffered streams (currently only file). */
char *i_stream_next_line(struct istream *stream);
+/* Like i_stream_next_line(), but reads for more data if needed. Returns NULL
+ if more data is needed or error occured. */
+char *i_stream_read_next_line(struct istream *stream);
/* Returns pointer to beginning of read data, or NULL if there's no data
buffered. */
const unsigned char *i_stream_get_data(struct istream *stream, size_t *size);