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

Side by Side Diff: base/file_util_posix.cc

Issue 12321062: base: Move MemoryMappedFile out of file_util.h and into its own header file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chrome_frame again Created 7 years, 10 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 852 }
853 memset(&info.stat, 0, sizeof(info.stat)); 853 memset(&info.stat, 0, sizeof(info.stat));
854 } 854 }
855 entries->push_back(info); 855 entries->push_back(info);
856 } 856 }
857 857
858 closedir(dir); 858 closedir(dir);
859 return true; 859 return true;
860 } 860 }
861 861
862 ///////////////////////////////////////////////
863 // MemoryMappedFile
864
865 MemoryMappedFile::MemoryMappedFile()
866 : file_(base::kInvalidPlatformFileValue),
867 data_(NULL),
868 length_(0) {
869 }
870
871 bool MemoryMappedFile::MapFileToMemoryInternal() {
872 base::ThreadRestrictions::AssertIOAllowed();
873
874 struct stat file_stat;
875 if (fstat(file_, &file_stat) == base::kInvalidPlatformFileValue) {
876 DLOG(ERROR) << "Couldn't fstat " << file_ << ", errno " << errno;
877 return false;
878 }
879 length_ = file_stat.st_size;
880
881 data_ = static_cast<uint8*>(
882 mmap(NULL, length_, PROT_READ, MAP_SHARED, file_, 0));
883 if (data_ == MAP_FAILED)
884 DLOG(ERROR) << "Couldn't mmap " << file_ << ", errno " << errno;
885
886 return data_ != MAP_FAILED;
887 }
888
889 void MemoryMappedFile::CloseHandles() {
890 base::ThreadRestrictions::AssertIOAllowed();
891
892 if (data_ != NULL)
893 munmap(data_, length_);
894 if (file_ != base::kInvalidPlatformFileValue)
895 ignore_result(HANDLE_EINTR(close(file_)));
896
897 data_ = NULL;
898 length_ = 0;
899 file_ = base::kInvalidPlatformFileValue;
900 }
901
902 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, 862 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info,
903 const base::Time& cutoff_time) { 863 const base::Time& cutoff_time) {
904 return static_cast<time_t>(find_info.stat.st_mtime) >= cutoff_time.ToTimeT(); 864 return static_cast<time_t>(find_info.stat.st_mtime) >= cutoff_time.ToTimeT();
905 } 865 }
906 866
907 bool NormalizeFilePath(const FilePath& path, FilePath* normalized_path) { 867 bool NormalizeFilePath(const FilePath& path, FilePath* normalized_path) {
908 FilePath real_path_result; 868 FilePath real_path_result;
909 if (!RealPath(path, &real_path_result)) 869 if (!RealPath(path, &real_path_result))
910 return false; 870 return false;
911 871
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 kFileSystemRoot, path, kRootUid, allowed_group_ids); 1091 kFileSystemRoot, path, kRootUid, allowed_group_ids);
1132 } 1092 }
1133 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 1093 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
1134 1094
1135 int GetMaximumPathComponentLength(const FilePath& path) { 1095 int GetMaximumPathComponentLength(const FilePath& path) {
1136 base::ThreadRestrictions::AssertIOAllowed(); 1096 base::ThreadRestrictions::AssertIOAllowed();
1137 return pathconf(path.value().c_str(), _PC_NAME_MAX); 1097 return pathconf(path.value().c_str(), _PC_NAME_MAX);
1138 } 1098 }
1139 1099
1140 } // namespace file_util 1100 } // namespace file_util
OLDNEW
« 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