string: Simplify return value of for_each_line().
authorAndre Noll <maan@systemlinux.org>
Mon, 25 Mar 2013 17:30:56 +0000 (17:30 +0000)
committerAndre Noll <maan@systemlinux.org>
Thu, 2 May 2013 17:56:09 +0000 (19:56 +0200)
No caller used this function for counting lines, so simplify it by always
returning the number of bytes not processed.

string.c

index c22dc7cfce51954c65ecd407857e0352b09a53f3..c0a1951d83fd934c019413dc985e3d70247b3566 100644 (file)
--- a/string.c
+++ b/string.c
@@ -370,10 +370,10 @@ __malloc char *para_hostname(void)
  * incomplete line) is moved to the beginning of the buffer if FELF_READ_ONLY is
  * unset.
  *
- * \return If \p FELF_READ_ONLY is not set in \a flags, this function returns
- * the number of bytes not handled to \p line_handler, otherwise the number of
- * complete lines. On errors the negative error code of the \p line_handler is
- * returned.
+ * \return On success this function returns the number of bytes not handled to
+ * \p line_handler. The only possible error is a negative return value from the
+ * line handler. In this case processing stops and the return value of the line
+ * handler is returned to indicate failure.
  *
  * \sa \ref for_each_line_flags.
  */
@@ -415,10 +415,8 @@ int for_each_line(unsigned flags, char *buf, size_t size,
                        return ret;
                start = ++end;
        }
-       if (flags & FELF_READ_ONLY)
-               return num_lines;
        i = buf + size - start;
-       if (i && i != size)
+       if (i && i != size && !(flags & FELF_READ_ONLY))
                memmove(buf, start, i);
        return i;
 }