From 4b82681c65b6bea328d82cc717a854f34ed808a9 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Tue, 9 Nov 2004 20:27:23 +0000 Subject: [PATCH] Fix isBytecodeFile to correctly recognized compressed bytecode too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17655 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/System/Win32/Path.cpp | 11 +++++++---- lib/System/Win32/Path.inc | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/System/Win32/Path.cpp b/lib/System/Win32/Path.cpp index e22b0354b7e..08a3d402e88 100644 --- a/lib/System/Win32/Path.cpp +++ b/lib/System/Win32/Path.cpp @@ -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 diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index e22b0354b7e..08a3d402e88 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -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