fd_file: never report Close failure on linux.
close() will always succeed on linux, even if it returns -1 and sets
errno. Always report success, to avoid potential double closes.
Test: fd_file_test on host
Change-Id: I7d47b978645beff6b769f2ae05c32b0e328e433d
diff --git a/runtime/base/unix_file/fd_file.cc b/runtime/base/unix_file/fd_file.cc
index 58b047f..792c581 100644
--- a/runtime/base/unix_file/fd_file.cc
+++ b/runtime/base/unix_file/fd_file.cc
@@ -163,13 +163,18 @@
moveUp(GuardState::kClosed, nullptr);
}
+#if defined(__linux__)
+ // close always succeeds on linux, even if failure is reported.
+ UNUSED(result);
+#else
if (result == -1) {
return -errno;
- } else {
- fd_ = -1;
- file_path_ = "";
- return 0;
}
+#endif
+
+ fd_ = -1;
+ file_path_ = "";
+ return 0;
}
int FdFile::Flush() {