From: Sascha Hauer <s.hauer@pengutronix.de>
To: Trent Piepho <trent.piepho@igorinstitute.com>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 2/3] libfile: Add copy_fd()
Date: Wed, 23 Jun 2021 08:43:33 +0200 [thread overview]
Message-ID: <20210623064333.GS9782@pengutronix.de> (raw)
In-Reply-To: <CAMHeXxM61PR2HMzZiDG5SFQ7exLPwhMsQFCtqznsfdiadwaZvQ@mail.gmail.com>
On Tue, Jun 22, 2021 at 11:24:57PM -0700, Trent Piepho wrote:
> 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;
Indeed, thanks. I'll change it like that.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-06-23 6:44 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
2021-06-23 6:43 ` Sascha Hauer [this message]
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=20210623064333.GS9782@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=trent.piepho@igorinstitute.com \
/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