From: Timo Sirainen Date: Mon, 10 Mar 2003 00:36:08 +0000 (+0200) Subject: Added i_stream_read_next_line() X-Git-Tag: 1.1.alpha1~4813 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89e195dfb5c4b0efd9b9f459771a4467674e5b1f;p=thirdparty%2Fdovecot%2Fcore.git Added i_stream_read_next_line() --HG-- branch : HEAD --- diff --git a/src/auth/db-passwd-file.c b/src/auth/db-passwd-file.c index 6c12e8195f..8dbbb9685e 100644 --- a/src/auth/db-passwd-file.c +++ b/src/auth/db-passwd-file.c @@ -142,14 +142,7 @@ static void passwd_file_open(struct passwd_file *pw) 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 */ diff --git a/src/lib-settings/settings.c b/src/lib-settings/settings.c index a27dae6070..e0fc8b0821 100644 --- a/src/lib-settings/settings.c +++ b/src/lib-settings/settings.c @@ -73,13 +73,7 @@ void settings_read(const char *path, settings_callback_t *callback, 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 */ diff --git a/src/lib/istream.c b/src/lib/istream.c index 34fafd3439..4cc4991576 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -189,6 +189,19 @@ char *i_stream_next_line(struct istream *stream) 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; diff --git a/src/lib/istream.h b/src/lib/istream.h index 84e3b10813..37b0add4a6 100644 --- a/src/lib/istream.h +++ b/src/lib/istream.h @@ -57,10 +57,13 @@ void i_stream_skip(struct istream *stream, uoff_t count); /* 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);