diff --git a/src/dwarfsck_main.cpp b/src/dwarfsck_main.cpp index e3a6737c..9cad1a38 100644 --- a/src/dwarfsck_main.cpp +++ b/src/dwarfsck_main.cpp @@ -19,6 +19,8 @@ * along with dwarfs. If not, see . */ +#include +#include #include #include #include @@ -29,6 +31,7 @@ #include #include #include +#include #include #include "dwarfs/error.h" @@ -141,8 +144,13 @@ int dwarfsck_main(int argc, sys_char** argv) { std::cout << folly::toPrettyJson(fs.metadata_as_dynamic()) << "\n"; } else if (print_header) { if (auto hdr = filesystem_v2::header(mm, fsopts.image_offset)) { - std::cout << std::string_view( - reinterpret_cast(hdr->data()), hdr->size()); +#ifdef _WIN32 + ::_setmode(STDOUT_FILENO, _O_BINARY); +#endif + if (::write(STDOUT_FILENO, hdr->data(), hdr->size()) < 0) { + LOG_ERROR << "error writing header: " << ::strerror(errno); + return 1; + } } else { LOG_ERROR << "filesystem does not contain a header"; return 1;