string: Simplify for_each_line().
authorAndre Noll <maan@systemlinux.org>
Mon, 25 Mar 2013 17:16:14 +0000 (17:16 +0000)
committerAndre Noll <maan@systemlinux.org>
Thu, 2 May 2013 17:56:09 +0000 (19:56 +0200)
No user calls this with line_hander == NULL, so remove the special treatment
of this case.

string.c

index 68e1f8a2d31735dae1e663bf833d2937e6466f4c..c22dc7cfce51954c65ecd407857e0352b09a53f3 100644 (file)
--- a/string.c
+++ b/string.c
@@ -358,25 +358,22 @@ __malloc char *para_hostname(void)
  * \param line_handler The custom function.
  * \param private_data Pointer passed to \a line_handler.
  *
- * If \p line_handler is \p NULL, the function returns the number of complete
- * lines in \p buf.
- *
- * Otherwise, \p line_handler is called for each complete line in \p buf. The
- * first argument to \p line_handler is (a copy of) the current line, and \p
+ * For each complete line in \p buf, \p line_handler is called. The first
+ * argument to \p line_handler is (a copy of) the current line, and \p
  * private_data is passed as the second argument.  If the \p FELF_READ_ONLY
  * flag is unset, a pointer into \a buf is passed to the line handler,
- * otherwise a pointer to a copy of each line is passed instead.  This copy is
- * freed immediately after the line handler returns.
+ * otherwise a pointer to a copy of the current line is passed instead. This
+ * copy is freed immediately after the line handler returns.
  *
  * The function returns if \p line_handler returns a negative value or no more
  * lines are in the buffer.  The rest of the buffer (last chunk containing an
  * incomplete line) is moved to the beginning of the buffer if FELF_READ_ONLY is
  * unset.
  *
- * \return If \p line_handler is not \p NULL and FELF_READ_ONLY is not set,
- * this function returns the number of bytes not handled to \p line_handler,
- * otherwise number of complete lines.  On errors the negative error code of
- * the \p line_handler is returned.
+ * \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.
  *
  * \sa \ref for_each_line_flags.
  */
@@ -402,10 +399,6 @@ int for_each_line(unsigned flags, char *buf, size_t size,
                } else
                        end = next_cr;
                num_lines++;
-               if (!line_handler) {
-                       start = ++end;
-                       continue;
-               }
                if (flags & FELF_READ_ONLY) {
                        size_t s = end - start;
                        char *b = para_malloc(s + 1);
@@ -422,7 +415,7 @@ int for_each_line(unsigned flags, char *buf, size_t size,
                        return ret;
                start = ++end;
        }
-       if (!line_handler || (flags & FELF_READ_ONLY))
+       if (flags & FELF_READ_ONLY)
                return num_lines;
        i = buf + size - start;
        if (i && i != size)