adb: keep file flags in fdevent_install.
Bug: 24615098
Change-Id: Ia791ecbe612f09aca3bbd5787513f121fae54da5
diff --git a/adb_utils.cpp b/adb_utils.cpp
index 7ff5c3d..f7b2e4e 100644
--- a/adb_utils.cpp
+++ b/adb_utils.cpp
@@ -229,3 +229,19 @@
std::string perror_str(const char* msg) {
return android::base::StringPrintf("%s: %s", msg, strerror(errno));
}
+
+#if !defined(_WIN32)
+bool set_file_block_mode(int fd, bool block) {
+ int flags = fcntl(fd, F_GETFL, 0);
+ if (flags == -1) {
+ PLOG(ERROR) << "failed to fcntl(F_GETFL) for fd " << fd;
+ return false;
+ }
+ flags = block ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
+ if (fcntl(fd, F_SETFL, flags) != 0) {
+ PLOG(ERROR) << "failed to fcntl(F_SETFL) for fd " << fd << ", flags " << flags;
+ return false;
+ }
+ return true;
+}
+#endif