summaryrefslogtreecommitdiffstats
path: root/base/file_util_posix.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-16 22:55:17 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-16 22:55:17 +0000
commitcb6037d67847a6341eea166baf1d4051667a0b88 (patch)
tree2b766762057e96d758385b96e2a576d7b6690d54 /base/file_util_posix.cc
parentf9be34d622561d5599603b41d1c43d595e503426 (diff)
downloadchromium_src-cb6037d67847a6341eea166baf1d4051667a0b88.zip
chromium_src-cb6037d67847a6341eea166baf1d4051667a0b88.tar.gz
chromium_src-cb6037d67847a6341eea166baf1d4051667a0b88.tar.bz2
reland 31875. Revert was:
------ Revert 31875 to see whether it fixes reliability bot. BUG=25677 TEST=None ------ TBR=huanr Review URL: http://codereview.chromium.org/397017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r--base/file_util_posix.cc42
1 files changed, 9 insertions, 33 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 1a05d79..a269d3f 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -667,47 +667,23 @@ bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries,
// MemoryMappedFile
MemoryMappedFile::MemoryMappedFile()
- : data_(NULL),
+ : file_(base::kInvalidPlatformFileValue),
+ data_(NULL),
length_(0) {
}
-bool MemoryMappedFile::Initialize(const base::FileDescriptor& fd) {
- if (IsValid())
- return false;
-
- file_ = fd;
-
- if (!MapFileToMemoryInternal()) {
- CloseHandles();
- return false;
- }
-
- return true;
-}
-
-bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
- file_ = base::FileDescriptor(open(file_name.value().c_str(), O_RDONLY), true);
-
- if (file_.fd == -1) {
- LOG(ERROR) << "Couldn't open " << file_name.value();
- return false;
- }
-
- return MapFileToMemoryInternal();
-}
-
bool MemoryMappedFile::MapFileToMemoryInternal() {
struct stat file_stat;
- if (fstat(file_.fd, &file_stat) == -1) {
- LOG(ERROR) << "Couldn't fstat " << file_.fd << ", errno " << errno;
+ if (fstat(file_, &file_stat) == base::kInvalidPlatformFileValue) {
+ LOG(ERROR) << "Couldn't fstat " << file_ << ", errno " << errno;
return false;
}
length_ = file_stat.st_size;
data_ = static_cast<uint8*>(
- mmap(NULL, length_, PROT_READ, MAP_SHARED, file_.fd, 0));
+ mmap(NULL, length_, PROT_READ, MAP_SHARED, file_, 0));
if (data_ == MAP_FAILED)
- LOG(ERROR) << "Couldn't mmap " << file_.fd << ", errno " << errno;
+ LOG(ERROR) << "Couldn't mmap " << file_ << ", errno " << errno;
return data_ != MAP_FAILED;
}
@@ -715,12 +691,12 @@ bool MemoryMappedFile::MapFileToMemoryInternal() {
void MemoryMappedFile::CloseHandles() {
if (data_ != NULL)
munmap(data_, length_);
- if (file_.auto_close && file_.fd != -1)
- close(file_.fd);
+ if (file_ != base::kInvalidPlatformFileValue)
+ close(file_);
data_ = NULL;
length_ = 0;
- file_ = base::FileDescriptor();
+ file_ = base::kInvalidPlatformFileValue;
}
} // namespace file_util