Re: [PATCH 2/3] libfile: Add copy_fd()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux