MC/Mach-O: Shuffle enums a bit to make it harder to inadvertently use the wrong
[oota-llvm.git] / lib / Object / ObjectFile.cpp
index 29aa4b8bdb81319850709792b667b5445a04099c..aa483f357f5deba8d828a931d3158d4776024f23 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Object/ObjectFile.h"
+#include "llvm/ADT/OwningPtr.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/system_error.h"
 
-namespace llvm {
-namespace object {
+using namespace llvm;
+using namespace object;
 
 ObjectFile::ObjectFile(MemoryBuffer *Object)
   : MapFile(Object) {
@@ -47,7 +50,7 @@ ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) {
     case sys::Mach_O_Executable_FileType:
     case sys::Mach_O_FixedVirtualMemorySharedLib_FileType:
     case sys::Mach_O_Core_FileType:
-    case sys::Mach_O_PreloadExectuable_FileType:
+    case sys::Mach_O_PreloadExecutable_FileType:
     case sys::Mach_O_DynamicallyLinkedSharedLib_FileType:
     case sys::Mach_O_DynamicLinker_FileType:
     case sys::Mach_O_Bundle_FileType:
@@ -60,9 +63,9 @@ ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) {
   }
 }
 
-ObjectFile *ObjectFile::createObjectFile(const sys::Path &ObjectPath) {
-  return createObjectFile(MemoryBuffer::getFile(ObjectPath.c_str()));
+ObjectFile *ObjectFile::createObjectFile(StringRef ObjectPath) {
+  OwningPtr<MemoryBuffer> File;
+  if (error_code ec = MemoryBuffer::getFile(ObjectPath, File))
+    return NULL;
+  return createObjectFile(File.take());
 }
-
-} // end namespace object
-} // end namespace llvm