Support/PathV2: Add identify_magic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123548 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer
2011-01-15 20:39:36 +00:00
parent b6516aeef1
commit 28f0ed5c9d
5 changed files with 49 additions and 40 deletions

View File

@ -703,6 +703,16 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) {
return success;
}
error_code identify_magic(const Twine &path, LLVMFileType &result) {
SmallString<32> Magic;
error_code ec = get_magic(path, Magic.capacity(), Magic);
if (ec && ec != errc::value_too_large)
return ec;
result = IdentifyFileType(Magic.data(), Magic.size());
return success;
}
namespace {
error_code remove_all_r(StringRef path, file_type ft, uint32_t &count) {
if (ft == file_type::directory_file) {