aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/FileUtilities.cpp
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2003-11-11 21:53:50 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2003-11-11 21:53:50 +0000
commita2302ffe78b2afe334f3b41eaf8a745b5608fa23 (patch)
tree300637494af59efe56f64996a9c6d334f3dfe18a /lib/Support/FileUtilities.cpp
parentf33d00f0d8ffb41a57ce86672de5c3590903db01 (diff)
Move IsArchive and IsBytecode here from gccld. Refactor into CheckMagic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9901 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/FileUtilities.cpp')
-rw-r--r--lib/Support/FileUtilities.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp
index 15ea03fb50..3262ecce31 100644
--- a/lib/Support/FileUtilities.cpp
+++ b/lib/Support/FileUtilities.cpp
@@ -20,6 +20,35 @@
#include <iostream>
#include <cstdio>
+/// CheckMagic - Returns true IFF the file named FN begins with Magic. FN must
+/// name a readable file.
+///
+bool CheckMagic (const std::string &FN, const std::string &Magic) {
+ char buf[1 + Magic.size ()];
+ std::ifstream f (FN.c_str ());
+ f.read (buf, Magic.size ());
+ buf[Magic.size ()] = '\0';
+ return Magic == buf;
+}
+
+/// IsArchive - Returns true IFF the file named FN appears to be a "ar" library
+/// archive. The file named FN must exist.
+///
+bool IsArchive(const std::string &FN) {
+ // Inspect the beginning of the file to see if it contains the "ar"
+ // library archive format magic string.
+ return CheckMagic (FN, "!<arch>\012");
+}
+
+/// IsBytecode - Returns true IFF the file named FN appears to be an LLVM
+/// bytecode file. The file named FN must exist.
+///
+bool IsBytecode(const std::string &FN) {
+ // Inspect the beginning of the file to see if it contains the LLVM
+ // bytecode format magic string.
+ return CheckMagic (FN, "llvm");
+}
+
/// FileOpenable - Returns true IFF Filename names an existing regular
/// file which we can successfully open.
///