mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-13 06:16:55 -04:00
Force binary mode on stdout when writing header in dwarfsck
This commit is contained in:
parent
2dfc39eb6f
commit
0c3ee8550c
@ -19,6 +19,8 @@
|
|||||||
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cerrno>
|
||||||
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -29,6 +31,7 @@
|
|||||||
#include <folly/FileUtil.h>
|
#include <folly/FileUtil.h>
|
||||||
#include <folly/String.h>
|
#include <folly/String.h>
|
||||||
#include <folly/json.h>
|
#include <folly/json.h>
|
||||||
|
#include <folly/portability/Unistd.h>
|
||||||
#include <folly/system/HardwareConcurrency.h>
|
#include <folly/system/HardwareConcurrency.h>
|
||||||
|
|
||||||
#include "dwarfs/error.h"
|
#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";
|
std::cout << folly::toPrettyJson(fs.metadata_as_dynamic()) << "\n";
|
||||||
} else if (print_header) {
|
} else if (print_header) {
|
||||||
if (auto hdr = filesystem_v2::header(mm, fsopts.image_offset)) {
|
if (auto hdr = filesystem_v2::header(mm, fsopts.image_offset)) {
|
||||||
std::cout << std::string_view(
|
#ifdef _WIN32
|
||||||
reinterpret_cast<char const*>(hdr->data()), hdr->size());
|
::_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 {
|
} else {
|
||||||
LOG_ERROR << "filesystem does not contain a header";
|
LOG_ERROR << "filesystem does not contain a header";
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user