in tools/file_concat/main.cc [30:65]
int main(int argc, const char* argv[]) {
if (argc < 2) {
std::cout << "Usage: " << argv[0] << " <output> <inputs...>" << std::endl;
return kUsageError;
}
std::string output_path(argv[1]);
std::ofstream output(output_path, std::ofstream::binary);
if (!output) {
std::cerr << "Could not open output file " << output_path << std::endl;
return kIOError;
}
for (int i = 2; i < argc; i++) {
std::string input_path(argv[i]);
std::ifstream input(input_path, std::ifstream::binary);
if (!input) {
std::cerr << "Could not open input file " << output_path << std::endl;
return kIOError;
}
char buffer[kBufferSize];
while (input) {
if (!input.read(buffer, kBufferSize) && !input.eof()) {
std::cerr << "Error reading from " << input_path << std::endl;
return kIOError;
}
if (!output.write(buffer, input.gcount())) {
std::cerr << "Error writing to " << output_path << std::endl;
return kIOError;
}
}
}
return kOk;
}