MC/Mach-O: Shuffle enums a bit to make it harder to inadvertently use the wrong
[oota-llvm.git] / lib / Object / ObjectFile.cpp
index c2ab4a5dbbcf19a5d3aacbcc9214b670c0b0e2b5..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/System/Path.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/system_error.h"
 
 using namespace llvm;
 using namespace object;
@@ -48,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:
@@ -62,5 +64,8 @@ ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) {
 }
 
 ObjectFile *ObjectFile::createObjectFile(StringRef ObjectPath) {
-  return createObjectFile(MemoryBuffer::getFile(ObjectPath));
+  OwningPtr<MemoryBuffer> File;
+  if (error_code ec = MemoryBuffer::getFile(ObjectPath, File))
+    return NULL;
+  return createObjectFile(File.take());
 }