21 const bool ok = ofs.good();
24 std::cerr <<
"ERROR: write failed (disk full or I/O error): " << path << std::endl;
25 std::ofstream ferr(
"err messages.txt", std::ios::app);
26 ferr <<
"ERROR: write failed (disk full or I/O error): " << path <<
"\n";
43 std::ofstream ofs(path, std::ios::binary);
45 ofs.write(data,
static_cast<std::streamsize
>(
size));
49 std::cerr <<
"FATAL: failed to write " <<
size <<
" bytes to " << path
50 <<
" (disk full?) — restart data would be corrupt." << std::endl;
65 std::ifstream ifs(path, std::ios::binary | std::ios::ate);
67 std::cerr <<
"ERROR: cannot open " << path << std::endl;
70 const auto sz =
static_cast<std::streamsize
>(ifs.tellg());
72 out.resize(
static_cast<size_t>(sz));
73 ifs.read(out.data(), sz);
74 if (ifs.gcount() != sz) {
75 std::cerr <<
"ERROR: short read from " << path <<
" (" << ifs.gcount()
76 <<
" of " << sz <<
" bytes)" << std::endl;
void write_file_or_die(const std::string &path, const char *data, size_t size)
Write an entire buffer to a binary file (truncating it); fatal on any failure.
bool checked_close(std::ofstream &ofs, const std::string &path)
Flush and close an output stream and report a failed write.
bool read_file_verified(const std::string &path, std::vector< char > &out)
Read an entire binary file into out, verifying the byte count.
int size
Total number of MPI processes.