diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-06-05 08:55:54 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-06-05 08:55:54 +0200 |
| commit | 81fa478a642b25715adecf27c283e6f15334d705 (patch) | |
| tree | 6e0bb3c889cfb9d38bac6b735512459cbbce064b /cabinet/main.cpp | |
| parent | 1ca48e3790e69e63c3789a32d541e4086e849030 (diff) | |
| download | cabinet-81fa478a642b25715adecf27c283e6f15334d705.tar.xz cabinet-81fa478a642b25715adecf27c283e6f15334d705.zip | |
magic: implement file descriptor support
Diffstat (limited to 'cabinet/main.cpp')
| -rw-r--r-- | cabinet/main.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/cabinet/main.cpp b/cabinet/main.cpp index 77a73ca..db2d43b 100644 --- a/cabinet/main.cpp +++ b/cabinet/main.cpp @@ -1,7 +1,8 @@ #include <cabinet/magic.hpp> +#include <fcntl.h> + #include <cstdlib> -#include <filesystem> #include <iostream> #include <print> @@ -15,19 +16,19 @@ auto main(int argc, char ** argv) -> int return EXIT_FAILURE; } - auto magic = cab::magic::open(flags::follow_symlinks | flags::mime_type); + auto magic = cab::magic::open(flags::follow_symlinks | flags::mime_type | flags::forward_errors); 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]}); + auto fd = open(argv[1], O_RDONLY); + auto mime_type = magic->process(fd); 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()); } |
