Remove attribution from file headers, per discussion on llvmdev.
[oota-llvm.git] / lib / System / Win32 / MappedFile.inc
index 3112a93a8d37337a4de479151437d7337c08c845..28dbb9856d475fda50228af1597390ea6a02d45b 100644 (file)
@@ -2,8 +2,8 @@
 // 
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Jeff Cohen and is distributed under the 
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 // 
 //===----------------------------------------------------------------------===//
 //
@@ -16,7 +16,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "Win32.h"
-#include "llvm/System/MappedFile.h"
 #include "llvm/System/Process.h"
 
 namespace llvm {
@@ -28,7 +27,7 @@ struct sys::MappedFileInfo {
   size_t size;
 };
 
-void MappedFile::initialize() {
+bool MappedFile::initialize(std::string* ErrMsg) {
   assert(!info_);
   info_ = new MappedFileInfo;
   info_->hFile = INVALID_HANDLE_VALUE;
@@ -43,7 +42,8 @@ void MappedFile::initialize() {
   if (info_->hFile == INVALID_HANDLE_VALUE) {
     delete info_;
     info_ = NULL;
-    ThrowError(std::string("Can't open file: ") + path_.get());
+    return MakeErrMsg(ErrMsg,
+      std::string("Can't open file: ") + path_.toString());
   }
 
   LARGE_INTEGER size;
@@ -52,8 +52,11 @@ void MappedFile::initialize() {
     CloseHandle(info_->hFile);
     delete info_;
     info_ = NULL;
-    ThrowError(std::string("Can't get size of file: ") + path_.get());
+    return MakeErrMsg(ErrMsg, 
+      std::string("Can't get size of file: ") + path_.toString());
   }
+
+  return false;
 }
 
 void MappedFile::terminate() {
@@ -76,7 +79,7 @@ void MappedFile::unmap() {
   }
 }
 
-void* MappedFile::map() {
+void* MappedFile::map(std::string* ErrMsg) {
   if (!isMapped()) {
     DWORD prot = PAGE_READONLY;
     if (options_ & EXEC_ACCESS)
@@ -84,26 +87,29 @@ void* MappedFile::map() {
     else if (options_ & WRITE_ACCESS)
       prot = PAGE_READWRITE;
     info_->hMapping = CreateFileMapping(info_->hFile, NULL, prot, 0, 0, NULL);
-    if (info_->hMapping == NULL)
-      ThrowError(std::string("Can't map file: ") + path_.get());
+    if (info_->hMapping == NULL) {
+      MakeErrMsg(ErrMsg, std::string("Can't map file: ") + path_.toString());
+      return 0;
+    }
 
     prot = (options_ & WRITE_ACCESS) ? FILE_MAP_WRITE : FILE_MAP_READ;
     base_ = MapViewOfFileEx(info_->hMapping, prot, 0, 0, 0, NULL);
     if (base_ == NULL) {
       CloseHandle(info_->hMapping);
       info_->hMapping = NULL;
-      ThrowError(std::string("Can't map file: ") + path_.get());
+      MakeErrMsg(ErrMsg, std::string("Can't map file: ") + path_.toString());
+      return 0;
     }
   }
   return base_;
 }
 
-size_t MappedFile::size() {
+size_t MappedFile::size() const {
   assert(info_ && "MappedFile not initialized");
   return info_->size;
 }
 
-void MappedFile::size(size_t new_size) {
+bool MappedFile::size(size_t new_size, std::string* ErrMsg) {
   assert(info_ && "MappedFile not initialized");
 
   // Take the mapping out of memory.
@@ -118,16 +124,17 @@ void MappedFile::size(size_t new_size) {
     LARGE_INTEGER eof;
     eof.QuadPart = new_size;
     if (!SetFilePointerEx(info_->hFile, eof, NULL, FILE_BEGIN))
-      ThrowError(std::string("Can't set end of file: ") + path_.get());
+      return MakeErrMsg(ErrMsg, 
+        std::string("Can't set end of file: ") + path_.toString());
     if (!SetEndOfFile(info_->hFile))
-      ThrowError(std::string("Can't set end of file: ") + path_.get());
+      return MakeErrMsg(ErrMsg, 
+        std::string("Can't set end of file: ") + path_.toString());
     info_->size = new_size;
   }
 
   // Remap the file.
-  map();
+  return map(ErrMsg);
 }
 
 }
 
-// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab