diff options
author | Roland Lutz <rlutz@hedmen.org> | 2017-07-10 14:03:17 +0200 |
---|---|---|
committer | Roland Lutz <rlutz@hedmen.org> | 2017-09-04 15:51:03 +0200 |
commit | 450306dfb14a866f070f7370286880564316d1a9 (patch) | |
tree | ce9f4b5f2ccda2a06b5f5d9b9bb68cb0657bb5d6 | |
parent | 21b2504aedf2faea144c81a00dbf19261a7ce85f (diff) | |
download | icestorm-450306dfb14a866f070f7370286880564316d1a9.tar.gz icestorm-450306dfb14a866f070f7370286880564316d1a9.tar.bz2 icestorm-450306dfb14a866f070f7370286880564316d1a9.zip |
icemulti: Give more information about I/O errors
-rw-r--r-- | icemulti/icemulti.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index 32719d3..48e2512 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -58,7 +58,7 @@ static void write_bytes(std::ostream &ofs, uint32_t &file_offset, } static void write_file(std::ostream &ofs, uint32_t &file_offset, - std::istream &ifs) + std::istream &ifs, const char *filename) { const size_t bufsize = 8192; uint8_t *buffer = new uint8_t[bufsize]; @@ -66,7 +66,7 @@ static void write_file(std::ostream &ofs, uint32_t &file_offset, while(!ifs.eof()) { ifs.read(reinterpret_cast<char *>(buffer), bufsize); if (ifs.bad()) - error("Read error on input image"); + error("can't read input image `%s': %s\n", filename, strerror(errno)); write_bytes(ofs, file_offset, buffer, ifs.gcount()); } @@ -82,11 +82,12 @@ static void pad_to(std::ostream &ofs, uint32_t &file_offset, uint32_t target) } class Image { + const char *filename; std::ifstream ifs; uint32_t offs; public: - Image(const char *filename) : ifs(filename, std::ifstream::binary) {} + Image(const char *filename) : filename(filename), ifs(filename, std::ifstream::binary) {} size_t size(); void write(std::ostream &ofs, uint32_t &file_offset); @@ -104,7 +105,7 @@ size_t Image::size() void Image::write(std::ostream &ofs, uint32_t &file_offset) { - write_file(ofs, file_offset, ifs); + write_file(ofs, file_offset, ifs, filename); } class Header { @@ -268,7 +269,7 @@ int main(int argc, char **argv) if (outfile_name != NULL) { ofs.open(outfile_name, std::ofstream::binary); if (!ofs.is_open()) - error("Failed to open output file.\n"); + error("can't open output file `%s': %s\n", outfile_name, strerror(errno)); osp = &ofs; } else { osp = &std::cout; |