/****************************************************************************** * This program reads bytes from a binary file and copies them to another file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #include #include #include using namespace Utils; using namespace std; void copy_binary_file(string from_filespec, string to_filespec) { ifstream ifh(filesystem::path(from_filespec).c_str(), ios_base::binary); ofstream ofh(filesystem::path(to_filespec).c_str(), ios_base::binary); if (!ifh.good()) { throw ios_base::failure("Problem opening input file!"); } if (!ofh.good()) { throw ios_base::failure("Problem opening output file!"); } unsigned char c; while (Utils::getbytes(ifh, c)) { ofh.put(c); } ifh.close(); ofh.close(); } int main(int argc, char **argv) { if (argc != 3) { cout << "Syntax: " << argv[0] << " {fromFilespec} {toFilespec}" << endl; exit(1); } string from_filespec(argv[1]); string to_filespec(argv[2]); try { copy_binary_file(from_filespec, to_filespec); } catch (ios_base::failure ex) { cout << "Error: " << Utils::exceptionMessage(ex) << endl; } return 0; }