[RFC 3/3] libbb: read_full: use read return instead size
Sascha Hauer
s.hauer at pengutronix.de
Fri Feb 28 09:21:18 EST 2014
On Fri, Feb 28, 2014 at 09:03:34AM +0100, Alexander Aring wrote:
> On Fri, Feb 28, 2014 at 08:44:28AM +0100, Alexander Aring wrote:
> > Signed-off-by: Alexander Aring <alex.aring at gmail.com>
> > ---
> > lib/libbb.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/libbb.c b/lib/libbb.c
> > index 189a170..c8d0835 100644
> > --- a/lib/libbb.c
> > +++ b/lib/libbb.c
> > @@ -162,7 +162,7 @@ int read_full(int fd, void *buf, size_t size)
> > int now;
> > int total = 0;
> >
> > - while (size) {
> > + while (now) {
> > now = read(fd, buf, size);
> > if (now == 0)
> > return total;
> and this should be a:
>
> do {
> ...
> } while (now);
>
> sry, it's only to demonstrate the issue.
'now' will never be 0 at the end of the loop, so you could equally well
write while(1). With this change we try to read as long as we read
something last time, even if there's nothing left to read (size is 0).
What issue do you see with this function?
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list