diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-12-14 18:42:13 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-12-14 18:42:13 +0000 |
commit | c936ad12089e02e948928329ffec48d4bc3b83d4 (patch) | |
tree | 74a6a12c788505129d20679aae458a65fa92616c /llvm/lib/System/Win32/Path.cpp | |
parent | 4bc39bef799341cd6170002b01897b5461c1178f (diff) | |
download | bcm5719-llvm-c936ad12089e02e948928329ffec48d4bc3b83d4.tar.gz bcm5719-llvm-c936ad12089e02e948928329ffec48d4bc3b83d4.zip |
Add the getMagicNumber method.
Patch contributed by Henrik Bach. Thanks Henrik!
llvm-svn: 18933
Diffstat (limited to 'llvm/lib/System/Win32/Path.cpp')
-rw-r--r-- | llvm/lib/System/Win32/Path.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/System/Win32/Path.cpp b/llvm/lib/System/Win32/Path.cpp index 88e20cd354f..f6e4c3b4763 100644 --- a/llvm/lib/System/Win32/Path.cpp +++ b/llvm/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; +} + } } |