Introduce qemu_write_full()
A variant of write(2) which handles partial write. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
5d757b563d
commit
7b5f699dbd
27
osdep.c
27
osdep.c
@ -243,6 +243,33 @@ int qemu_open(const char *name, int flags, ...)
|
|||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
/*
|
/*
|
||||||
* Creates a pipe with FD_CLOEXEC set on both file descriptors
|
* Creates a pipe with FD_CLOEXEC set on both file descriptors
|
||||||
|
@ -161,6 +161,7 @@ void qemu_mutex_lock_iothread(void);
|
|||||||
void qemu_mutex_unlock_iothread(void);
|
void qemu_mutex_unlock_iothread(void);
|
||||||
|
|
||||||
int qemu_open(const char *name, int flags, ...);
|
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);
|
void qemu_set_cloexec(int fd);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
Loading…
Reference in New Issue
Block a user