blob: 24a65075fd983d2e96b0c9b56672ed20e5e9cf33 [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
17#ifndef HAVE_SYS_UIO_H
18
Colin Cross9227bd32013-07-23 16:59:20 -070019#include <log/uio.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080020#include <unistd.h>
21
22int readv( int fd, struct iovec* vecs, int count )
23{
24 int total = 0;
25
26 for ( ; count > 0; count--, vecs++ ) {
Mark Salyzyn168021c2014-01-06 08:14:11 -080027 char* buf = vecs->iov_base;
28 int len = vecs->iov_len;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080029
30 while (len > 0) {
31 int ret = read( fd, buf, len );
32 if (ret < 0) {
33 if (total == 0)
34 total = -1;
35 goto Exit;
36 }
37 if (ret == 0)
38 goto Exit;
39
40 total += ret;
41 buf += ret;
42 len -= ret;
43 }
44 }
45Exit:
46 return total;
47}
48
49int writev( int fd, const struct iovec* vecs, int count )
50{
51 int total = 0;
52
53 for ( ; count > 0; count--, vecs++ ) {
Mark Salyzyn168021c2014-01-06 08:14:11 -080054 const char* buf = vecs->iov_base;
55 int len = vecs->iov_len;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080056
57 while (len > 0) {
58 int ret = write( fd, buf, len );
59 if (ret < 0) {
60 if (total == 0)
61 total = -1;
62 goto Exit;
63 }
64 if (ret == 0)
65 goto Exit;
66
67 total += ret;
68 buf += ret;
69 len -= ret;
70 }
71 }
72Exit:
73 return total;
74}
75
76#endif /* !HAVE_SYS_UIO_H */