mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-27 04:18:42 +00:00
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
This commit is contained in:
1 parent
f33d00f0d8
commit
a2302ffe78
1 file changed
+29
@@ -20,6 +20,35 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdio>
|
#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
|
/// FileOpenable - Returns true IFF Filename names an existing regular
|
||||||
/// file which we can successfully open.
|
/// file which we can successfully open.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in new issue
Block a user