From 9adea5f7f7a23ef4a1231289a36a94c52347b142 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sun, 21 Apr 2013 12:01:06 +0200 Subject: win32: add readv/writev emulation Commit e9d8fbf (qemu-file: do not use stdio for qemu_fdopen, 2013-03-27) introduced a usage of writev, which mingw32 does not have. Even though qemu_fdopen itself is not used on mingw32, the future-proof solution is to add an implementation of it. This is simple and similar to how we emulate sendmsg/recvmsg in util/iov.c. Some files include osdep.h without qemu-common.h, so move the definition of iovec to osdep.h too, and include osdep.h from qemu-common.h unconditionally (protection against including files when NEED_CPU_H is defined is not needed since the removal of AREG0). Signed-off-by: Paolo Bonzini --- util/osdep.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'util/osdep.c') diff --git a/util/osdep.c b/util/osdep.c index 6ae5aaf..685c8ae 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -429,3 +429,46 @@ int socket_init(void) #endif return 0; } + +#ifndef CONFIG_IOVEC +/* helper function for iov_send_recv() */ +static ssize_t +readv_writev(int fd, const struct iovec *iov, int iov_cnt, bool do_write) +{ + unsigned i = 0; + ssize_t ret = 0; + while (i < iov_cnt) { + ssize_t r = do_write + ? write(fd, iov[i].iov_base, iov[i].iov_len) + : read(fd, iov[i].iov_base, iov[i].iov_len); + if (r > 0) { + ret += r; + } else if (!r) { + break; + } else if (errno == EINTR) { + continue; + } else { + /* else it is some "other" error, + * only return if there was no data processed. */ + if (ret == 0) { + ret = -1; + } + break; + } + i++; + } + return ret; +} + +ssize_t +readv(int fd, const struct iovec *iov, int iov_cnt) +{ + return readv_writev(fd, iov, iov_cnt, false); +} + +ssize_t +writev(int fd, const struct iovec *iov, int iov_cnt) +{ + return readv_writev(fd, iov, iov_cnt, true); +} +#endif -- cgit v1.1