blob: 24a65075fd983d2e96b0c9b56672ed20e5e9cf33 [file] [log] [blame]
Colin Crosse355ded2013-07-23 16:59:20 -07001/*
Mark Salyzyn023eabf2014-01-06 08:14:11 -08002 * Copyright (C) 2007-2014 The Android Open Source Project
Colin Crosse355ded2013-07-23 16:59:20 -07003 *
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
19#include <log/uio.h>
20#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 Salyzyn023eabf2014-01-06 08:14:11 -080027 char* buf = vecs->iov_base;
28 int len = vecs->iov_len;
Colin Crosse355ded2013-07-23 16:59:20 -070029
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 Salyzyn023eabf2014-01-06 08:14:11 -080054 const char* buf = vecs->iov_base;
55 int len = vecs->iov_len;
Colin Crosse355ded2013-07-23 16:59:20 -070056
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 */