From: Trent Piepho <trent.piepho@igorinstitute.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 2/3] libfile: Add copy_fd()
Date: Tue, 22 Jun 2021 23:24:57 -0700 [thread overview]
Message-ID: <CAMHeXxM61PR2HMzZiDG5SFQ7exLPwhMsQFCtqznsfdiadwaZvQ@mail.gmail.com> (raw)
In-Reply-To: <20210623043359.18391-3-s.hauer@pengutronix.de>
On Tue, Jun 22, 2021 at 9:34 PM Sascha Hauer <s.hauer@pengutronix.de> wrote:
> + while (1) {
> + int now, wr;
> +
> + now = read(in, buf, bs);
> + if (now < 0) {
> + ret = now;
> + goto err;
> + }
> +
> + if (!now)
> + break;
> +
> + wr = write_full(out, buf, now);
> + if (wr < 0) {
> + ret = wr;
> + goto err;
> + }
> + }
> +
> + ret = 0;
> +err:
> + free(buf);
> +
> + return ret;
This can be quite a bit shorter:
while (1) {
ret = read(in, buf, bs);
if (ret <= 0)
break;
ret = write_full(out, buf, ret);
if (ret < 0)
break;
}
free(buf)
return ret;
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-06-23 6:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-23 4:33 [PATCH 0/3] firmware: Add support for compressed images Sascha Hauer
2021-06-23 4:33 ` [PATCH 1/3] filetype: Add function to check if a filetype is a compressed file Sascha Hauer
2021-06-23 4:33 ` [PATCH 2/3] libfile: Add copy_fd() Sascha Hauer
2021-06-23 6:24 ` Trent Piepho [this message]
2021-06-23 6:43 ` Sascha Hauer
2021-06-23 4:33 ` [PATCH 3/3] firmware: add support for compressed images Sascha Hauer
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=CAMHeXxM61PR2HMzZiDG5SFQ7exLPwhMsQFCtqznsfdiadwaZvQ@mail.gmail.com \
--to=trent.piepho@igorinstitute.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox