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

Unified Diff: base/file_util_posix.cc

Issue 14073: Implement the memory mapped file class for posix. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years 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 6919)
+++ base/file_util_posix.cc (working copy)
@@ -12,6 +12,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/errno.h>
+#include <sys/mman.h>
#include <sys/stat.h>
#include <time.h>
@@ -378,6 +379,9 @@
return !ret;
}
+///////////////////////////////////////////////
+// FileEnumerator
+
FileEnumerator::FileEnumerator(const FilePath& root_path,
bool recursive,
FileEnumerator::FILE_TYPE file_type)
@@ -479,5 +483,41 @@
return Next();
}
+///////////////////////////////////////////////
+// MemoryMappedFile
+MemoryMappedFile::MemoryMappedFile()
+ : file_(-1),
+ data_(NULL),
+ length_(0) {
+}
+
+bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
+ file_ = open(file_name.value().c_str(), O_RDONLY);
+ if (file_ == -1)
+ return false;
+
+ struct stat file_stat;
+ if (fstat(file_, &file_stat) == -1)
+ return false;
+ length_ = file_stat.st_size;
+
+ data_ = static_cast<uint8*>(mmap(NULL, length_, PROT_READ, MAP_SHARED,
Peter Kasting 2008/12/12 21:27:49 Super-tiny nit: It'd be nice to make the wrapping
+ file_, 0));
+ if (data_ == MAP_FAILED)
+ data_ = NULL;
+ return data_ != NULL;
+}
+
+void MemoryMappedFile::CloseHandles() {
+ if (data_ != NULL)
+ munmap(data_, length_);
+ if (file_ != -1)
+ close(file_);
+
+ data_ = NULL;
+ length_ = 0;
+ file_ = -1;
+}
+
} // 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