OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. |
| 5 */ |
| 6 #include <unistd.h> |
| 7 #include <sys/uio.h> |
| 8 #include <errno.h> |
| 9 |
| 10 int writev(int fd, const struct iovec *iov, int iovcnt) { |
| 11 int i = 0, ret = 0, n = 0, len = 0; |
| 12 char* base; |
| 13 errno = 0; |
| 14 while (i < iovcnt) { |
| 15 len = iov->iov_len; |
| 16 base = iov->iov_base; |
| 17 while (len > 0) { |
| 18 ret = write(fd, base, len); |
| 19 if (ret < 0 && n == 0) return -1; |
| 20 if (ret <= 0) return n; |
| 21 errno = 0; |
| 22 n += ret; |
| 23 len -= ret; |
| 24 base += ret; |
| 25 } |
| 26 iov++; |
| 27 i++; |
| 28 } |
| 29 return n; |
| 30 } |
| 31 |
| 32 ssize_t readv(int fd, const struct iovec *iov, int iovcnt) { |
| 33 int i = 0, ret = 0, n = 0, len = 0; |
| 34 char* base; |
| 35 errno = 0; |
| 36 while (i < iovcnt) { |
| 37 len = iov->iov_len; |
| 38 base = iov->iov_base; |
| 39 while (len > 0) { |
| 40 ret = read(fd, base, len); |
| 41 if (ret < 0 && n == 0) return -1; |
| 42 if (ret <= 0) return n; |
| 43 errno = 0; |
| 44 n += ret; |
| 45 len -= ret; |
| 46 base += ret; |
| 47 } |
| 48 iov++; |
| 49 i++; |
| 50 } |
| 51 return n; |
| 52 } |
OLD | NEW |