adb/base: allow use of unique_fd inside adb.
adb implements its own file descriptor emulation layer on Windows,
which requires the use of adb_close instead of close throughout the
codebase. Add a template argument to unique_fd that allows for this.
Bug: http://b/28347842
Change-Id: I6397261f4973d49f2f8e04257bf67b348585bb63
diff --git a/adb/adb_utils.h b/adb/adb_utils.h
index abf481b..22eb4d2 100644
--- a/adb/adb_utils.h
+++ b/adb/adb_utils.h
@@ -20,6 +20,7 @@
#include <string>
#include <android-base/macros.h>
+#include <android-base/unique_fd.h>
void close_stdin();
@@ -51,6 +52,14 @@
std::string* error);
// Helper to automatically close an FD when it goes out of scope.
+struct AdbCloser {
+ static void Close(int fd) {
+ adb_close(fd);
+ }
+};
+
+using unique_fd = android::base::unique_fd_impl<AdbCloser>;
+
class ScopedFd {
public:
ScopedFd() {
diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index 3586da8..639f8eb 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -29,8 +29,9 @@
#include <string>
#include <vector>
-// Include this before open/unlink are defined as macros below.
+// Include this before open/close/unlink are defined as macros below.
#include <android-base/errors.h>
+#include <android-base/unique_fd.h>
#include <android-base/utf8.h>
/*