blob: 8d237ce398e815beaffd44ccefbe9e679a3af07d [file] [log] [blame]
Dan Albertcc731cc2015-02-24 21:26:58 -08001/*
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
Dan Albertcc731cc2015-02-24 21:26:58 -080023/*
24 * Reads exactly len bytes from fd into buf.
25 *
26 * Returns false if there is an error or if EOF was reached before len bytes
27 * were read. If EOF was found, errno will be set to 0.
28 *
29 * If this function fails, the contents of buf are undefined.
30 */
31bool ReadFdExactly(int fd, void *buf, size_t len);
32
33/*
34 * Writes exactly len bytes from buf to fd.
35 *
36 * Returns false if there is an error or if the fd was closed before the write
37 * completed. If the other end of the fd (such as in a socket, pipe, or fifo),
38 * is closed, errno will be set to 0.
39 */
40bool WriteFdExactly(int fd, const void *buf, size_t len);
41
42/* Same as WriteFdExactly, but with an implicit len = strlen(buf). */
43bool WriteStringFully(int fd, const char* str);
44
Dan Albertcc731cc2015-02-24 21:26:58 -080045#endif /* ADB_IO_H */