Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Unified Diff: base/file_util_posix.cc

Issue 397014: Revert 31875 to see whether it fixes reliability bot. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_posix.cc
===================================================================
--- base/file_util_posix.cc (revision 32064)
+++ base/file_util_posix.cc (working copy)
@@ -667,23 +667,47 @@
// MemoryMappedFile
MemoryMappedFile::MemoryMappedFile()
- : file_(base::kInvalidPlatformFileValue),
- data_(NULL),
+ : 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_, &file_stat) == base::kInvalidPlatformFileValue) {
- LOG(ERROR) << "Couldn't fstat " << file_ << ", errno " << errno;
+ if (fstat(file_.fd, &file_stat) == -1) {
+ LOG(ERROR) << "Couldn't fstat " << file_.fd << ", errno " << errno;
return false;
}
length_ = file_stat.st_size;
data_ = static_cast<uint8*>(
- mmap(NULL, length_, PROT_READ, MAP_SHARED, file_, 0));
+ mmap(NULL, length_, PROT_READ, MAP_SHARED, file_.fd, 0));
if (data_ == MAP_FAILED)
- LOG(ERROR) << "Couldn't mmap " << file_ << ", errno " << errno;
+ LOG(ERROR) << "Couldn't mmap " << file_.fd << ", errno " << errno;
return data_ != MAP_FAILED;
}
@@ -691,12 +715,12 @@
void MemoryMappedFile::CloseHandles() {
if (data_ != NULL)
munmap(data_, length_);
- if (file_ != base::kInvalidPlatformFileValue)
- close(file_);
+ if (file_.auto_close && file_.fd != -1)
+ close(file_.fd);
data_ = NULL;
length_ = 0;
- file_ = base::kInvalidPlatformFileValue;
+ file_ = base::FileDescriptor();
}
} // namespace file_util
« no previous file with comments | « base/file_util.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698