mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-27 14:34:58 +00:00
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:
parent
5761805d27
commit
3b0cc78c60
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user