aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-08-22 16:04:22 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-08-22 16:04:22 +0000
commit6d045fcdcd4fe83f51050f6601726d29b2689526 (patch)
treea8408eccbfed4f0dcfec0e0f83c98cb1dac8dcd2 /lib
parentad42ea73563c204285f47fbf598b01915d2f3044 (diff)
downloadexternal_llvm-6d045fcdcd4fe83f51050f6601726d29b2689526.zip
external_llvm-6d045fcdcd4fe83f51050f6601726d29b2689526.tar.gz
external_llvm-6d045fcdcd4fe83f51050f6601726d29b2689526.tar.bz2
For PR797:
Make MappedFile not throw any exceptions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29816 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/System/Unix/MappedFile.inc25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/System/Unix/MappedFile.inc b/lib/System/Unix/MappedFile.inc
index 341ee25..ef959ba 100644
--- a/lib/System/Unix/MappedFile.inc
+++ b/lib/System/Unix/MappedFile.inc
@@ -39,7 +39,7 @@ struct sys::MappedFileInfo {
off_t Size;
};
-void MappedFile::initialize() {
+bool MappedFile::initialize(std::string* ErrMsg) {
int mode = 0;
if (options_ & READ_ACCESS)
if (options_ & WRITE_ACCESS)
@@ -50,17 +50,20 @@ void MappedFile::initialize() {
mode = O_WRONLY;
int FD = ::open(path_.c_str(), mode);
- if (FD < 0)
- ThrowErrno(std::string("Can't open file: ") + path_.toString());
-
+ if (FD < 0) {
+ MakeErrMsg(ErrMsg, "can't open file '" + path_.toString() + "'");
+ return true;
+ }
struct stat sbuf;
if(::fstat(FD, &sbuf) < 0) {
+ MakeErrMsg(ErrMsg, "can't stat file '"+ path_.toString() + "'");
::close(FD);
- ThrowErrno(std::string("Can't stat file: ") + path_.toString());
+ return true;
}
info_ = new MappedFileInfo;
info_->FD = FD;
info_->Size = sbuf.st_size;
+ return false;
}
void MappedFile::terminate() {
@@ -79,7 +82,7 @@ void MappedFile::unmap() {
}
}
-void* MappedFile::map() {
+void* MappedFile::map(std::string* ErrMsg) {
assert(info_ && "MappedFile not initialized");
if (!isMapped()) {
int prot = PROT_NONE;
@@ -106,8 +109,10 @@ void* MappedFile::map() {
Process::GetPageSize();
base_ = ::mmap(0, map_size, prot, flags, info_->FD, 0);
- if (base_ == MAP_FAILED)
- ThrowErrno(std::string("Can't map file:") + path_.toString());
+ if (base_ == MAP_FAILED) {
+ MakeErrMsg(ErrMsg, "Can't map file:" + path_.toString());
+ return 0;
+ }
}
return base_;
}
@@ -139,8 +144,8 @@ void MappedFile::size(size_t new_size) {
::write(info_->FD, "\0", 1);
}
- // Seek to current end of file.
- this->map();
+ // Put the mapping back into memory.
+ this->map(0);
}
}