#ifndef CABINET_MAGIC_HPP #define CABINET_MAGIC_HPP #include #include #include #include #include #include #include #include #include namespace cab { struct magic { enum struct flags : decltype(MAGIC_NONE) { none = MAGIC_NONE, print_debug = MAGIC_DEBUG, follow_symlinks = MAGIC_SYMLINK, inspect_compressed = MAGIC_COMPRESS, inspect_devices = MAGIC_DEVICES, mime_type = MAGIC_MIME_TYPE, mime_encoding = MAGIC_MIME_ENCODING, mime = MAGIC_MIME, all_matches = MAGIC_CONTINUE, check_database = MAGIC_CHECK, preserve_access_time = MAGIC_PRESERVE_ATIME, raw = MAGIC_RAW, forward_errors = MAGIC_ERROR, apple = MAGIC_APPLE, extensions = MAGIC_EXTENSION, transparent_compression = MAGIC_COMPRESS_TRANSP, emx_dont_check_application_type = MAGIC_NO_CHECK_APPTYPE, no_elf_details = MAGIC_NO_CHECK_ELF, no_text_encodings = MAGIC_NO_CHECK_ENCODING, no_magic_files = MAGIC_NO_CHECK_SOFT, dont_inspect_tar = MAGIC_NO_CHECK_TAR, no_text_files = MAGIC_NO_CHECK_TEXT, no_tokens = MAGIC_NO_CHECK_TOKENS, no_json = MAGIC_NO_CHECK_JSON, no_csv = MAGIC_NO_CHECK_CSV, no_simh = MAGIC_NO_CHECK_SIMH, }; auto static open(flags flags, std::string_view database = {}) noexcept -> std::expected; ~magic(); magic(magic const &) = delete; magic(magic && other) noexcept; auto operator=(magic const &) -> magic & = delete; auto operator=(magic && other) noexcept -> magic &; auto process(std::filesystem::path path) -> std::expected; auto process(int file_descriptor) -> std::expected; auto process(std::span data) -> std::expected; private: auto handle_result(char const * result) -> std::expected; explicit magic(::magic_t cookie) noexcept; ::magic_t m_cookie{}; }; auto swap(magic & lhs, magic & rhs) noexcept -> void; constexpr auto operator|(magic::flags lhs, magic::flags rhs) noexcept -> magic::flags { return static_cast(std::to_underlying(lhs) | std::to_underlying(rhs)); } } // namespace cab #endif