[llvm-commits] CVS: llvm/lib/System/Unix/MappedFile.inc

Reid Spencer reid at x10sys.com
Tue Aug 22 09:04:37 PDT 2006



Changes in directory llvm/lib/System/Unix:

MappedFile.inc updated: 1.16 -> 1.17
---
Log message:

For PR797: http://llvm.org/PR797 :
Make MappedFile not throw any exceptions.


---
Diffs of the changes:  (+15 -10)

 MappedFile.inc |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)


Index: llvm/lib/System/Unix/MappedFile.inc
diff -u llvm/lib/System/Unix/MappedFile.inc:1.16 llvm/lib/System/Unix/MappedFile.inc:1.17
--- llvm/lib/System/Unix/MappedFile.inc:1.16	Tue Jul 18 02:07:51 2006
+++ llvm/lib/System/Unix/MappedFile.inc	Tue Aug 22 11:04:22 2006
@@ -39,7 +39,7 @@
   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 @@
     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::map() {
+void* MappedFile::map(std::string* ErrMsg) {
   assert(info_ && "MappedFile not initialized");
   if (!isMapped()) {
     int prot = PROT_NONE;
@@ -106,8 +109,10 @@
       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 @@
     ::write(info_->FD, "\0", 1);
   }
 
-  // Seek to current end of file. 
-  this->map();
+  // Put the mapping back into memory.
+  this->map(0);
 }
 
 }






More information about the llvm-commits mailing list