Implement get_magic with generic tools and inline it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210716 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-06-11 22:53:00 +00:00
parent c6d63a3b0d
commit 07aac43603
4 changed files with 10 additions and 92 deletions

View File

@ -1022,13 +1022,17 @@ void directory_entry::replace_filename(const Twine &filename, file_status st) {
return file_magic::unknown;
}
error_code identify_magic(const Twine &path, file_magic &result) {
SmallString<32> Magic;
error_code ec = get_magic(path, Magic.capacity(), Magic);
if (ec && ec != std::errc::value_too_large)
return ec;
error_code identify_magic(const Twine &Path, file_magic &Result) {
int FD;
if (error_code EC = openFileForRead(Path, FD))
return EC;
result = identify_magic(Magic);
char Buffer[32];
int Length = read(FD, Buffer, sizeof(Buffer));
if (Length < 0)
return error_code(errno, generic_category());
Result = identify_magic(StringRef(Buffer, Length));
return error_code();
}