summaryrefslogtreecommitdiffstats
path: root/adb/adb_io.h
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2015-02-24 21:26:58 -0800
committerDan Albert <danalbert@google.com>2015-02-25 15:07:57 -0800
commitcc731cc76786b6bdc58764aad9924c0d0c8d645f (patch)
tree57906636c803e1ae089c2fcf2905d82488b0ba72 /adb/adb_io.h
parenta035d5003ea593322ba565df9a4f4d0dd6647acf (diff)
downloadcore-cc731cc76786b6bdc58764aad9924c0d0c8d645f.tar.gz
core-cc731cc76786b6bdc58764aad9924c0d0c8d645f.tar.bz2
core-cc731cc76786b6bdc58764aad9924c0d0c8d645f.zip
Test readx/writex (now renamed).
Renamed readx/writex to ReadFdExactly/WriteFdExactly respectively. These read/write a full fixed-size buffer. If the whole buffer cannot be read/written, these functions return an error. Rename write_string to WriteStringFully. Move the TEMP_FAILURE_RETRY definition in sysdeps.h out of the !Windows section. It seems Windows won't actually interrupt a call, but it's easier to just define it than to #ifdef each call. Change-Id: Ia8ddffa2a52764a2f9a281c96c937660e002b9b9
Diffstat (limited to 'adb/adb_io.h')
-rw-r--r--adb/adb_io.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/adb/adb_io.h b/adb/adb_io.h
new file mode 100644
index 000000000..7d09e7ba5
--- /dev/null
+++ b/adb/adb_io.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ADB_IO_H
+#define ADB_IO_H
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Reads exactly len bytes from fd into buf.
+ *
+ * Returns false if there is an error or if EOF was reached before len bytes
+ * were read. If EOF was found, errno will be set to 0.
+ *
+ * If this function fails, the contents of buf are undefined.
+ */
+bool ReadFdExactly(int fd, void *buf, size_t len);
+
+/*
+ * Writes exactly len bytes from buf to fd.
+ *
+ * Returns false if there is an error or if the fd was closed before the write
+ * completed. If the other end of the fd (such as in a socket, pipe, or fifo),
+ * is closed, errno will be set to 0.
+ */
+bool WriteFdExactly(int fd, const void *buf, size_t len);
+
+/* Same as WriteFdExactly, but with an implicit len = strlen(buf). */
+bool WriteStringFully(int fd, const char* str);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ADB_IO_H */