Mercurial > dovecot > original-hg > dovecot-1.2
changeset 1293:2f2c6335ed6d HEAD
Added i_stream_read_next_line()
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 10 Mar 2003 02:36:08 +0200 |
parents | 359334706e65 |
children | 9f8a41f1edae |
files | src/auth/db-passwd-file.c src/lib-settings/settings.c src/lib/istream.c src/lib/istream.h |
diffstat | 4 files changed, 19 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/auth/db-passwd-file.c Sun Mar 09 13:57:35 2003 +0200 +++ b/src/auth/db-passwd-file.c Mon Mar 10 02:36:08 2003 +0200 @@ -142,14 +142,7 @@ 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 */
--- a/src/lib-settings/settings.c Sun Mar 09 13:57:35 2003 +0200 +++ b/src/lib-settings/settings.c Mon Mar 10 02:36:08 2003 +0200 @@ -73,13 +73,7 @@ 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 */
--- a/src/lib/istream.c Sun Mar 09 13:57:35 2003 +0200 +++ b/src/lib/istream.c Mon Mar 10 02:36:08 2003 +0200 @@ -189,6 +189,19 @@ 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;
--- a/src/lib/istream.h Sun Mar 09 13:57:35 2003 +0200 +++ b/src/lib/istream.h Mon Mar 10 02:36:08 2003 +0200 @@ -57,10 +57,13 @@ /* 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);