Index: ports/glibc-compat/src/readv.c |
diff --git a/ports/glibc-compat/src/readv.c b/ports/glibc-compat/src/readv.c |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d1728c9dcbdab1371fd58691e1864fffb2c29b7f |
--- /dev/null |
+++ b/ports/glibc-compat/src/readv.c |
@@ -0,0 +1,29 @@ |
+/* Copyright 2015 The Native Client Authors. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. */ |
+ |
+#include <sys/uio.h> |
+#include <unistd.h> // unix(nacl) standards |
+#include <errno.h> |
+ |
+ssize_t readv (int fd, const struct iovec *iov, int iovcnt) { |
+ if (iovcnt < 0) { |
+ // #TODO(dt) add check for IOV_MAX |
+ errno = EINVAL; |
+ return -1; |
+ } |
+ ssize_t bytes_read = 0; |
+ ssize_t bytes_supposed_to_be_read = 0; |
+ int i; |
+ for (i = 0; i < (iovcnt); i++) { |
+ bytes_read += read(fd, iov[i].iov_base, iov[i].iov_len); |
+ bytes_supposed_to_be_read += iov[i].iov_len; |
+ //#TODO(dt) add check for (max) ssize_t allowed |
+ if (bytes_read != bytes_supposed_to_be_read) { |
+ // deliberately not setting errno here as it might override |
+ // errno set by read(...) |
+ return -1; |
+ } |
+ } |
+ return bytes_read; |
+} |