summaryrefslogtreecommitdiff
path: root/cabinet/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cabinet/main.cpp')
-rw-r--r--cabinet/main.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/cabinet/main.cpp b/cabinet/main.cpp
index ff35d34..3602142 100644
--- a/cabinet/main.cpp
+++ b/cabinet/main.cpp
@@ -1,8 +1,13 @@
#include <cabinet/magic.hpp>
#include <fcntl.h>
+#include <unistd.h>
+#include <array>
+#include <cerrno>
+#include <cstddef>
#include <cstdlib>
+#include <cstring>
#include <iostream>
#include <print>
@@ -23,12 +28,21 @@ auto main(int argc, char ** argv) -> int
return EXIT_FAILURE;
}
- auto fd = open(argv[1], O_RDONLY);
- auto mime_type = magic->process(fd);
+ auto fd = ::open(argv[1], O_RDONLY);
+ if (fd < 0)
+ {
+ std::println(std::cerr, "Failed to determine file type: {}", ::strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ std::array<std::byte, 512> buffer{};
+ ::read(fd, buffer.data(), buffer.size());
+ auto mime_type = magic->process(buffer);
if (!mime_type)
{
std::println(std::cerr, "Failed to determine file type: {}", mime_type.error().message());
return EXIT_FAILURE;
}
+
std::println("{}: {}", argv[1], mime_type.value());
}