Implement ScopedFD in terms of ScopedGeneric.
Move to a new file base/files/scoped_file.h. I will also add ScopedFILE to here (currently in file_util.h) later.
I think there is a crash in the old code in content/browser/zygote_host/zygote_host_impl_linux.cc that this patch should fix. The old ScopedFD took the address of something in a vector that is being modified.
I removed SafeScopedFD from content/common/sandbox_linux/sandbox_linux.cc since base's ScopedFD not CHECKs on close failure (this is a more recent addition).
Reland of https://codereview.chromium.org/191673003/
R=agl, viettrungluu
Review URL: https://codereview.chromium.org/202113004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257473 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: 42f558fdef03f1ec2261f554151d8a4d168919e4
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 96b5858..8ee55ff 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -26,6 +26,7 @@
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
+#include "base/files/scoped_file.h"
#include "base/files/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
@@ -2473,9 +2474,9 @@
char c = 0;
ASSERT_EQ(0, pipe(fds));
const int write_end = fds[1];
- file_util::ScopedFDCloser read_end_closer(fds);
+ base::ScopedFD read_end_closer(fds[0]);
{
- file_util::ScopedFDCloser write_end_closer(fds + 1);
+ base::ScopedFD write_end_closer(fds[1]);
}
// This is the only thread. This file descriptor should no longer be valid.
int ret = close(write_end);
@@ -2489,14 +2490,14 @@
#if defined(GTEST_HAS_DEATH_TEST)
void CloseWithScopedFD(int fd) {
- file_util::ScopedFDCloser fd_closer(&fd);
+ base::ScopedFD fd_closer(fd);
}
#endif
TEST(ScopedFD, ScopedFDCrashesOnCloseFailure) {
int fds[2];
ASSERT_EQ(0, pipe(fds));
- file_util::ScopedFDCloser read_end_closer(fds);
+ base::ScopedFD read_end_closer(fds[0]);
EXPECT_EQ(0, IGNORE_EINTR(close(fds[1])));
#if defined(GTEST_HAS_DEATH_TEST)
// This is the only thread. This file descriptor should no longer be valid.