blob: 77a73ca98636af62171336ac98580664e67e876c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <cabinet/magic.hpp>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <print>
using flags = cab::magic::flags;
auto main(int argc, char ** argv) -> int
{
if (argc != 2)
{
std::println(std::cerr, "Expected a filename");
return EXIT_FAILURE;
}
auto magic = cab::magic::open(flags::follow_symlinks | flags::mime_type);
if (!magic)
{
std::println(std::cerr, "Failed to initialize libmagic: {}", magic.error().message());
return EXIT_FAILURE;
}
auto mime_type = magic->process(std::filesystem::path{argv[1]});
if (!mime_type)
{
std::println(std::cerr, "Failed to determine file type: {}", mime_type.error());
return EXIT_FAILURE;
}
std::println("{}: {}", argv[1], mime_type.value());
}
|