]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added i_stream_read_next_line()
authorTimo Sirainen <tss@iki.fi>
Mon, 10 Mar 2003 00:36:08 +0000 (02:36 +0200)
committerTimo Sirainen <tss@iki.fi>
Mon, 10 Mar 2003 00:36:08 +0000 (02:36 +0200)
--HG--
branch : HEAD

src/auth/db-passwd-file.c
src/lib-settings/settings.c
src/lib/istream.c
src/lib/istream.h

index 6c12e8195f4799693d07ef5d581626cadac19ee5..8dbbb9685efce1334ac7ad7c5c821d966444e207 100644 (file)
@@ -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 */
 
index a27dae6070c83d3d307505d149f72895ff235521..e0fc8b08217860ce49389d59157aae1276a586ae 100644 (file)
@@ -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 */
index 34fafd3439166a451e8afdf36ec79851a6343397..4cc4991576c4ec027dd54829972da964293c6948 100644 (file)
@@ -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;
index 84e3b108136f7adf969fc4a9c8db18b46152cfc5..37b0add4a6a8c799adb5c553e78d30946af6a515 100644 (file)
@@ -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);