blob: e127202f299dfb53bb13ff0c49aec1b5bf09e7d0 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
Mark Salyzyn168021c2014-01-06 08:14:11 -08002 * Copyright (C) 2007-2014 The Android Open Source Project
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08003 *
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 Hughes111e3d32014-11-25 13:27:43 -080017#if defined(_WIN32)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080018
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080019#include <unistd.h>
20
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080021#include <log/uio.h>
22
Mark Salyzynfacf94c2016-03-01 13:45:42 -080023#include "log_portability.h"
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080024
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080025LIBLOG_ABI_PUBLIC int readv(int fd, struct iovec* vecs, int count) {
26 int total = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080027
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080028 for (; count > 0; count--, vecs++) {
29 char* buf = vecs->iov_base;
30 int len = vecs->iov_len;
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080031
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080032 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 Projectdd7bc332009-03-03 19:32:55 -080039
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080040 total += ret;
41 buf += ret;
42 len -= ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080043 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080044 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080045Exit:
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080046 return total;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080047}
48
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080049LIBLOG_ABI_PUBLIC int writev(int fd, const struct iovec* vecs, int count) {
50 int total = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080051
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080052 for (; count > 0; count--, vecs++) {
53 const char* buf = vecs->iov_base;
54 int len = vecs->iov_len;
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080055
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080056 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 Projectdd7bc332009-03-03 19:32:55 -080063
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080064 total += ret;
65 buf += ret;
66 len -= ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080067 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080068 }
Mark Salyzyn6d753fa2016-03-10 08:25:33 -080069Exit:
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080070 return total;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080071}
72
Elliott Hughes111e3d32014-11-25 13:27:43 -080073#endif