From 8a26f818896c6a02ebdb11d624cb9ef39f082df2 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Wed, 15 Sep 2010 22:45:45 +0000 Subject: [PATCH] System/Path: Add isObjectFile(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114032 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/System/Path.h | 11 +++++++++++ lib/System/Path.cpp | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h index 23b18d47145..27fa2c3f4fc 100644 --- a/include/llvm/System/Path.h +++ b/include/llvm/System/Path.h @@ -342,6 +342,17 @@ namespace sys { /// @brief Determine if the path references a dynamic library. bool isDynamicLibrary() const; + /// This function determines if the path name in the object references a + /// native object file by looking at it's magic number. The term object + /// file is defined as "an organized collection of separate, named + /// sequences of binary data." This covers the obvious file formats such as + /// COFF and ELF, but it also includes llvm ir bitcode, archives, + /// libraries, etc... + /// @returns true if the file starts with the magic number for an object + /// file. + /// @brief Determine if the path references an object file. + bool isObjectFile() const; + /// This function determines if the path name references an existing file /// or directory in the file system. /// @returns true if the pathname references an existing file or diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp index 4445c667d86..0026fd29df5 100644 --- a/lib/System/Path.cpp +++ b/lib/System/Path.cpp @@ -156,6 +156,20 @@ Path::isDynamicLibrary() const { return false; } +bool +Path::isObjectFile() const { + std::string Magic; + if (getMagicNumber(Magic, 64)) + if (IdentifyFileType(Magic.c_str(), + static_cast(Magic.length())) + != Unknown_FileType) { + // Everything in LLVMFileType is currently an object file. + return true; + } + + return false; +} + Path Path::FindLibrary(std::string& name) { std::vector LibPaths;