aboutsummaryrefslogtreecommitdiff
path: root/lib/System/Win32/Path.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-14 18:42:13 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-14 18:42:13 +0000
commit3b0cc78c600852c824e005e1d63df17994ba483c (patch)
treecbe031c80fd6cf2c687234fe2797b281ef3e1158 /lib/System/Win32/Path.cpp
parent5761805d277f0dc6707b086602c76fd8ae4d2935 (diff)
Add the getMagicNumber method.
Patch contributed by Henrik Bach. Thanks Henrik! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18933 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Win32/Path.cpp')
-rw-r--r--lib/System/Win32/Path.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/System/Win32/Path.cpp b/lib/System/Win32/Path.cpp
index 88e20cd354..f6e4c3b476 100644
--- a/lib/System/Win32/Path.cpp
+++ b/lib/System/Win32/Path.cpp
@@ -565,6 +565,25 @@ Path::destroyFile() {
return true;
}
+bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
+ if (!isFile())
+ return false;
+ assert(len < 1024 && "Request for magic string too long");
+ char* buf = (char*) alloca(1 + len);
+ std::ofstream ofs(path.c_str(),std::ofstream::in);
+ if (!ofs.is_open())
+ return false;
+ std::ifstream ifs(path.c_str());
+ if (!ifs.is_open())
+ return false;
+ ifs.read(buf, len);
+ ofs.close();
+ ifs.close();
+ buf[len] = '\0';
+ Magic = buf;
+ return true;
+}
+
}
}