Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* Copyright 2015 The Native Client Authors. All rights reserved. | |
| 2 * Use of this source code is governed by a BSD-style license that can be | |
| 3 * found in the LICENSE file. */ | |
| 4 | |
|
Sam Clegg
2015/08/25 18:25:30
Have you don't a sync recently? I think these fun
| |
| 5 #include <sys/uio.h> | |
| 6 #include <unistd.h> // unix(nacl) standards | |
| 7 #include <errno.h> | |
| 8 | |
| 9 ssize_t writev (int fd,const struct iovec *iov,int iovcnt) { | |
| 10 if (iovcnt < 0) { | |
| 11 // #TODO(dt) add check for IOV_MAX | |
| 12 errno = EINVAL; | |
| 13 return -1; | |
| 14 } | |
| 15 ssize_t bytes_written = 0; | |
| 16 ssize_t bytes_supposed_to_be_written = 0; | |
| 17 int i; | |
| 18 for (i = 0; i < (iovcnt); i++) { | |
| 19 bytes_written += write(fd, iov[i].iov_base, iov[i].iov_len); | |
| 20 bytes_supposed_to_be_written += iov[i].iov_len; | |
| 21 //#TODO(dt) add check for (max) ssize_t allowed | |
| 22 if (bytes_written != bytes_supposed_to_be_written) { | |
| 23 // deliberately not setting errno here as it might override | |
| 24 // errno set by write(...) | |
| 25 return -1; | |
| 26 } | |
| 27 } | |
| 28 return bytes_written; | |
| 29 } | |
| OLD | NEW |