qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 01/14] Introduce qemu_write_full()


From: malc
Subject: Re: [Qemu-devel] [PATCH 01/14] Introduce qemu_write_full()
Date: Thu, 31 Dec 2009 10:42:42 +0300 (MSK)

On Thu, 31 Dec 2009, Kirill A. Shutemov wrote:

> On Thu, Dec 31, 2009 at 4:00 AM, malc <address@hidden> wrote:
> > On Thu, 31 Dec 2009, Kirill A. Shutemov wrote:
> >
> >> A variant of write(2) which handles partial write.
> >>
> >> Signed-off-by: Kirill A. Shutemov <address@hidden>
> >> ---
> >>  osdep.c       |   27 +++++++++++++++++++++++++++
> >>  qemu-common.h |    1 +
> >>  2 files changed, 28 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/osdep.c b/osdep.c
> >> index e4836e7..d2406f2 100644
> >> --- a/osdep.c
> >> +++ b/osdep.c
> >> @@ -243,6 +243,33 @@ int qemu_open(const char *name, int flags, ...)
> >>      return ret;
> >>  }
> >>
> >> +/*
> >> + * A variant of write(2) which handles partial write.
> >> + *
> >> + * Return the number of bytes transferred.
> >> + * Set errno if fewer than `count' bytes are written.
> >> + */
> >> +ssize_t qemu_write_full(int fd, const void *buf, size_t count)
> >> +{
> >> +    ssize_t ret = 0;
> >> +    ssize_t total = 0;
> >> +
> >> +    while (count) {
> >> +        ret = write(fd, buf, count);
> >> +        if (ret < 0) {
> >> +            if (errno == EINTR)
> >> +                continue;
> >> +            break;
> >> +        }
> >> +
> >> +        count -= ret;
> >> +        buf += ret;
> >> +     total += ret;
> >> +    }
> >> +
> >> +    return total;
> >> +}
> >
> > This hides write errors.
> 
> Why do you think so? Return value < count indicates error.

It does not indicate _which_ error it was. 

-- 
mailto:address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]