From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: Re: [PATCH v2 1/4] Add cleaner line-by-line reading primitives Date: Tue, 28 Jun 2022 10:47:35 +1000 Message-ID: In-Reply-To: <20220627123632.3c25bb18@elisabeth> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1749225399650699591==" --===============1749225399650699591== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On Mon, Jun 27, 2022 at 12:36:32PM +0200, Stefano Brivio wrote: > On Fri, 24 Jun 2022 12:17:29 +1000 > David Gibson wrote: > > > [...] > > > > +/** > > + * lineread_get() - Read a single line from file (no allocation) > > + * @lr: Line reader state structure > > + * @line: Place a pointer to the next line in this variable > > + * > > + * Return: Length of line read on success, 0 on EOF, negative on error > > + */ > > +int lineread_get(struct lineread *lr, char **line) > > +{ > > + bool eof = false; > > + int line_len; > > + > > + while ((line_len = peek_line(lr, eof)) < 0) { > > + int rc; > > + > > + if ((lr->next_line + lr->count) == LINEREAD_BUFFER_SIZE) { > > + /* No space at end */ > > + if (lr->next_line == 0) { > > + /* Buffer is full, which means we've > > + * hit a line too long for us to > > + * process. FIXME: report error > > + * better > > + */ > > + return -1; > > + } > > + memmove(lr->buf, lr->buf + lr->next_line, lr->count); > > + lr->next_line = 0; > > + } > > + > > + /* Read more data into the end of buffer */ > > + rc = read(lr->fd, lr->buf + lr->next_line + lr->count, > > + LINEREAD_BUFFER_SIZE - lr->next_line - lr->count); > > + if (rc < 0) { > > + return rc; > > + } else if (rc == 0) { > > clang-tidy still complains about this one, and I think it's reasonable > (though not fundamental) to change it, because (rc < 0) is a clear > error condition we're returning right away. I'd just change this on > merge. Fair enough. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --===============1749225399650699591== Content-Type: application/pgp-signature Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc" MIME-Version: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