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
This commit is contained in:
Reid Spencer 2004-12-14 18:42:13 +00:00
parent 5761805d27
commit 3b0cc78c60
2 changed files with 38 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}