[Top][All Lists]
[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 05:00:01 +0300 (MSK) |
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.
> +
> #ifndef _WIN32
> /*
> * Creates a pipe with FD_CLOEXEC set on both file descriptors
> diff --git a/qemu-common.h b/qemu-common.h
> index 8630f8c..a8144cb 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -160,6 +160,7 @@ void qemu_mutex_lock_iothread(void);
> void qemu_mutex_unlock_iothread(void);
>
> int qemu_open(const char *name, int flags, ...);
> +ssize_t qemu_write_full(int fd, const void *buf, size_t count);
> void qemu_set_cloexec(int fd);
>
> #ifndef _WIN32
>
--
mailto:address@hidden
- [Qemu-devel] [PATCH 03/14] block/cow.c: fix warnings with _FORTIFY_SOURCE, (continued)
- [Qemu-devel] [PATCH 03/14] block/cow.c: fix warnings with _FORTIFY_SOURCE, Kirill A. Shutemov, 2009/12/30
- [Qemu-devel] [PATCH 04/14] block/qcow.c: fix warnings with _FORTIFY_SOURCE, Kirill A. Shutemov, 2009/12/30
- [Qemu-devel] [PATCH 05/14] block/vmdk.o: fix warnings with _FORTIFY_SOURCE, Kirill A. Shutemov, 2009/12/30
- [Qemu-devel] [PATCH 06/14] block/vvfat.c: fix warnings with _FORTIFY_SOURCE, Kirill A. Shutemov, 2009/12/30
- [Qemu-devel] [PATCH 07/14] block/qcow2.c: fix warnings with _FORTIFY_SOURCE, Kirill A. Shutemov, 2009/12/30
- [Qemu-devel] [PATCH 08/14] net/slirp.c: fix warning with _FORTIFY_SOURCE, Kirill A. Shutemov, 2009/12/30
- [Qemu-devel] [PATCH 09/14] usb-linux.c: fix warning with _FORTIFY_SOURCE, Kirill A. Shutemov, 2009/12/30
- [Qemu-devel] Re: [PATCH 06/14] block/vvfat.c: fix warnings with _FORTIFY_SOURCE, Paolo Bonzini, 2009/12/31
- Re: [Qemu-devel] [PATCH 04/14] block/qcow.c: fix warnings with _FORTIFY_SOURCE, malc, 2009/12/30
- [Qemu-devel] Re: [PATCH 04/14] block/qcow.c: fix warnings with _FORTIFY_SOURCE, Paolo Bonzini, 2009/12/31
Re: [Qemu-devel] [PATCH 01/14] Introduce qemu_write_full(),
malc <=
[Qemu-devel] Re: [PATCH 01/14] Introduce qemu_write_full(), Paolo Bonzini, 2009/12/31