[llvm-commits] CVS: llvm/lib/Support/FileUtilities.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Tue Nov 11 15:55:01 PST 2003
Changes in directory llvm/lib/Support:
FileUtilities.cpp updated: 1.9 -> 1.10
---
Log message:
Move IsArchive and IsBytecode here from gccld. Refactor into CheckMagic.
---
Diffs of the changes: (+29 -0)
Index: llvm/lib/Support/FileUtilities.cpp
diff -u llvm/lib/Support/FileUtilities.cpp:1.9 llvm/lib/Support/FileUtilities.cpp:1.10
--- llvm/lib/Support/FileUtilities.cpp:1.9 Tue Nov 11 12:27:21 2003
+++ llvm/lib/Support/FileUtilities.cpp Tue Nov 11 15:53:50 2003
@@ -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.
///
More information about the llvm-commits
mailing list