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

Side by Side Diff: base/file_util_posix.cc

Issue 372075: Use renderer spellchecker for windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: inline 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 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 } 660 }
661 661
662 closedir(dir); 662 closedir(dir);
663 return true; 663 return true;
664 } 664 }
665 665
666 /////////////////////////////////////////////// 666 ///////////////////////////////////////////////
667 // MemoryMappedFile 667 // MemoryMappedFile
668 668
669 MemoryMappedFile::MemoryMappedFile() 669 MemoryMappedFile::MemoryMappedFile()
670 : data_(NULL), 670 : file_(base::kInvalidPlatformFileValue),
671 data_(NULL),
671 length_(0) { 672 length_(0) {
672 } 673 }
673 674
674 bool MemoryMappedFile::Initialize(const base::FileDescriptor& fd) {
675 if (IsValid())
676 return false;
677
678 file_ = fd;
679
680 if (!MapFileToMemoryInternal()) {
681 CloseHandles();
682 return false;
683 }
684
685 return true;
686 }
687
688 bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
689 file_ = base::FileDescriptor(open(file_name.value().c_str(), O_RDONLY), true);
690
691 if (file_.fd == -1) {
692 LOG(ERROR) << "Couldn't open " << file_name.value();
693 return false;
694 }
695
696 return MapFileToMemoryInternal();
697 }
698
699 bool MemoryMappedFile::MapFileToMemoryInternal() { 675 bool MemoryMappedFile::MapFileToMemoryInternal() {
700 struct stat file_stat; 676 struct stat file_stat;
701 if (fstat(file_.fd, &file_stat) == -1) { 677 if (fstat(file_, &file_stat) == base::kInvalidPlatformFileValue) {
702 LOG(ERROR) << "Couldn't fstat " << file_.fd << ", errno " << errno; 678 LOG(ERROR) << "Couldn't fstat " << file_ << ", errno " << errno;
703 return false; 679 return false;
704 } 680 }
705 length_ = file_stat.st_size; 681 length_ = file_stat.st_size;
706 682
707 data_ = static_cast<uint8*>( 683 data_ = static_cast<uint8*>(
708 mmap(NULL, length_, PROT_READ, MAP_SHARED, file_.fd, 0)); 684 mmap(NULL, length_, PROT_READ, MAP_SHARED, file_, 0));
709 if (data_ == MAP_FAILED) 685 if (data_ == MAP_FAILED)
710 LOG(ERROR) << "Couldn't mmap " << file_.fd << ", errno " << errno; 686 LOG(ERROR) << "Couldn't mmap " << file_ << ", errno " << errno;
711 687
712 return data_ != MAP_FAILED; 688 return data_ != MAP_FAILED;
713 } 689 }
714 690
715 void MemoryMappedFile::CloseHandles() { 691 void MemoryMappedFile::CloseHandles() {
716 if (data_ != NULL) 692 if (data_ != NULL)
717 munmap(data_, length_); 693 munmap(data_, length_);
718 if (file_.auto_close && file_.fd != -1) 694 if (file_ != base::kInvalidPlatformFileValue)
719 close(file_.fd); 695 close(file_);
720 696
721 data_ = NULL; 697 data_ = NULL;
722 length_ = 0; 698 length_ = 0;
723 file_ = base::FileDescriptor(); 699 file_ = base::kInvalidPlatformFileValue;
724 } 700 }
725 701
726 } // namespace file_util 702 } // 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