Fix isBytecodeFile to correctly recognized compressed bytecode too.
authorReid Spencer <rspencer@reidspencer.com>
Tue, 9 Nov 2004 20:27:23 +0000 (20:27 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 9 Nov 2004 20:27:23 +0000 (20:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17655 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Win32/Path.cpp
lib/System/Win32/Path.inc

index e22b0354b7e220c0767e544180330b96d3ac80b7..08a3d402e8806eef0ed880d17d889fa054ee1df1 100644 (file)
@@ -242,10 +242,13 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
 
 bool 
 Path::isBytecodeFile() const {
-  if (readable()) {
-    return hasMagicNumber("llvm");
-  }
-  return false;
+  char buffer[ 4];
+  buffer[0] = 0;
+  std::ifstream f(path.c_str());
+  f.read(buffer, 4);
+  if (f.bad())
+    ThrowErrno("can't read file signature");
+  return 0 == memcmp(buffer,"llvc",4) || 0 == memcmp(buffer,"llvm",4);
 }
 
 bool
index e22b0354b7e220c0767e544180330b96d3ac80b7..08a3d402e8806eef0ed880d17d889fa054ee1df1 100644 (file)
@@ -242,10 +242,13 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
 
 bool 
 Path::isBytecodeFile() const {
-  if (readable()) {
-    return hasMagicNumber("llvm");
-  }
-  return false;
+  char buffer[ 4];
+  buffer[0] = 0;
+  std::ifstream f(path.c_str());
+  f.read(buffer, 4);
+  if (f.bad())
+    ThrowErrno("can't read file signature");
+  return 0 == memcmp(buffer,"llvc",4) || 0 == memcmp(buffer,"llvm",4);
 }
 
 bool