Dan Albert | 66a91b0 | 2015-02-24 21:26:58 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 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 | |
| 17 | #ifndef ADB_IO_H |
| 18 | #define ADB_IO_H |
| 19 | |
| 20 | #include <stdbool.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
| 27 | /* |
| 28 | * Reads exactly len bytes from fd into buf. |
| 29 | * |
| 30 | * Returns false if there is an error or if EOF was reached before len bytes |
| 31 | * were read. If EOF was found, errno will be set to 0. |
| 32 | * |
| 33 | * If this function fails, the contents of buf are undefined. |
| 34 | */ |
| 35 | bool ReadFdExactly(int fd, void *buf, size_t len); |
| 36 | |
| 37 | /* |
| 38 | * Writes exactly len bytes from buf to fd. |
| 39 | * |
| 40 | * Returns false if there is an error or if the fd was closed before the write |
| 41 | * completed. If the other end of the fd (such as in a socket, pipe, or fifo), |
| 42 | * is closed, errno will be set to 0. |
| 43 | */ |
| 44 | bool WriteFdExactly(int fd, const void *buf, size_t len); |
| 45 | |
| 46 | /* Same as WriteFdExactly, but with an implicit len = strlen(buf). */ |
| 47 | bool WriteStringFully(int fd, const char* str); |
| 48 | |
| 49 | #ifdef __cplusplus |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | #endif /* ADB_IO_H */ |