The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
Mark Salyzyn | 168021c | 2014-01-06 08:14:11 -0800 | [diff] [blame] | 2 | * Copyright (C) 2007-2014 The Android Open Source Project |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Elliott Hughes | 111e3d3 | 2014-11-25 13:27:43 -0800 | [diff] [blame] | 17 | #if defined(_WIN32) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 19 | #include <unistd.h> |
| 20 | |
Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 21 | #include <log/uio.h> |
| 22 | |
Mark Salyzyn | facf94c | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 23 | #include "log_portability.h" |
Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 24 | |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 25 | LIBLOG_ABI_PUBLIC int readv(int fd, struct iovec* vecs, int count) { |
| 26 | int total = 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 27 | |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 28 | for (; count > 0; count--, vecs++) { |
| 29 | char* buf = vecs->iov_base; |
| 30 | int len = vecs->iov_len; |
Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 31 | |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 32 | while (len > 0) { |
| 33 | int ret = read(fd, buf, len); |
| 34 | if (ret < 0) { |
| 35 | if (total == 0) total = -1; |
| 36 | goto Exit; |
| 37 | } |
| 38 | if (ret == 0) goto Exit; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 39 | |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 40 | total += ret; |
| 41 | buf += ret; |
| 42 | len -= ret; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 43 | } |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 44 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 45 | Exit: |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 46 | return total; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 49 | LIBLOG_ABI_PUBLIC int writev(int fd, const struct iovec* vecs, int count) { |
| 50 | int total = 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 51 | |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 52 | for (; count > 0; count--, vecs++) { |
| 53 | const char* buf = vecs->iov_base; |
| 54 | int len = vecs->iov_len; |
Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 55 | |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 56 | while (len > 0) { |
| 57 | int ret = write(fd, buf, len); |
| 58 | if (ret < 0) { |
| 59 | if (total == 0) total = -1; |
| 60 | goto Exit; |
| 61 | } |
| 62 | if (ret == 0) goto Exit; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 63 | |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 64 | total += ret; |
| 65 | buf += ret; |
| 66 | len -= ret; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 67 | } |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 68 | } |
Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 69 | Exit: |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 70 | return total; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Elliott Hughes | 111e3d3 | 2014-11-25 13:27:43 -0800 | [diff] [blame] | 73 | #endif |