public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Subject: Re: [PATCH v2 1/4] Add cleaner line-by-line reading primitives
Date: Mon, 27 Jun 2022 12:36:32 +0200	[thread overview]
Message-ID: <20220627123632.3c25bb18@elisabeth> (raw)
In-Reply-To: <20220624021732.4062212-2-david@gibson.dropbear.id.au>

[-- Attachment #1: Type: text/plain, Size: 1390 bytes --]

On Fri, 24 Jun 2022 12:17:29 +1000
David Gibson <david(a)gibson.dropbear.id.au> 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.

-- 
Stefano


  reply	other threads:[~2022-06-27 10:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24  2:17 [PATCH v2 0/4] New line reading implementation David Gibson
2022-06-24  2:17 ` [PATCH v2 1/4] Add cleaner line-by-line reading primitives David Gibson
2022-06-27 10:36   ` Stefano Brivio [this message]
2022-06-28  0:47     ` David Gibson
2022-06-24  2:17 ` [PATCH v2 2/4] Parse resolv.conf with new lineread implementation David Gibson
2022-06-24  2:17 ` [PATCH v2 3/4] Use new lineread implementation for procfs_scan_listen() David Gibson
2022-06-24  2:17 ` [PATCH v2 4/4] Remove unused line_read() David Gibson
2022-07-06 17:46 ` [PATCH v2 0/4] New line reading implementation Stefano Brivio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220627123632.3c25bb18@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).