From: Andre Noll Date: Mon, 25 Mar 2013 17:16:14 +0000 (+0000) Subject: string: Simplify for_each_line(). X-Git-Tag: v0.4.13~33^2~3 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=d1f0f00fdedf1254b7e4119d8148a0da37b12a23;p=paraslash.git string: Simplify for_each_line(). No user calls this with line_hander == NULL, so remove the special treatment of this case. --- diff --git a/string.c b/string.c index 68e1f8a2..c22dc7cf 100644 --- 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)