| 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 |  | 
 | 25 | LIBLOG_ABI_PUBLIC int readv(int fd, struct iovec *vecs, int count) | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 26 | { | 
 | 27 |     int   total = 0; | 
 | 28 |  | 
 | 29 |     for ( ; count > 0; count--, vecs++ ) { | 
| Mark Salyzyn | 168021c | 2014-01-06 08:14:11 -0800 | [diff] [blame] | 30 |         char*  buf = vecs->iov_base; | 
 | 31 |         int    len = vecs->iov_len; | 
| Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 32 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 |         while (len > 0) { | 
 | 34 |             int  ret = read( fd, buf, len ); | 
 | 35 |             if (ret < 0) { | 
 | 36 |                 if (total == 0) | 
 | 37 |                     total = -1; | 
 | 38 |                 goto Exit; | 
 | 39 |             } | 
 | 40 |             if (ret == 0) | 
 | 41 |                 goto Exit; | 
 | 42 |  | 
 | 43 |             total += ret; | 
 | 44 |             buf   += ret; | 
 | 45 |             len   -= ret; | 
 | 46 |         } | 
 | 47 |     } | 
 | 48 | Exit: | 
 | 49 |     return total; | 
 | 50 | } | 
 | 51 |  | 
| Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 52 | LIBLOG_ABI_PUBLIC int writev(int fd, const struct iovec *vecs, int count) | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 53 | { | 
 | 54 |     int   total = 0; | 
 | 55 |  | 
 | 56 |     for ( ; count > 0; count--, vecs++ ) { | 
| Mark Salyzyn | 168021c | 2014-01-06 08:14:11 -0800 | [diff] [blame] | 57 |         const char*  buf = vecs->iov_base; | 
 | 58 |         int          len = vecs->iov_len; | 
| Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 59 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 60 |         while (len > 0) { | 
 | 61 |             int  ret = write( fd, buf, len ); | 
 | 62 |             if (ret < 0) { | 
 | 63 |                 if (total == 0) | 
 | 64 |                     total = -1; | 
 | 65 |                 goto Exit; | 
 | 66 |             } | 
 | 67 |             if (ret == 0) | 
 | 68 |                 goto Exit; | 
 | 69 |  | 
 | 70 |             total += ret; | 
 | 71 |             buf   += ret; | 
 | 72 |             len   -= ret; | 
 | 73 |         } | 
 | 74 |     } | 
| Mark Salyzyn | 6d753fa | 2016-03-10 08:25:33 -0800 | [diff] [blame] | 75 | Exit: | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 76 |     return total; | 
 | 77 | } | 
 | 78 |  | 
| Elliott Hughes | 111e3d3 | 2014-11-25 13:27:43 -0800 | [diff] [blame] | 79 | #endif |