improve error handling in connection_tester

This commit is contained in:
Arvid Norberg 2013-10-30 02:37:13 +00:00
parent c1b1d954be
commit 514f8797ad
1 changed files with 15 additions and 5 deletions

View File

@ -653,7 +653,13 @@ void generate_torrent(std::vector<char>& buf, int size, int num_files)
void generate_data(char const* path, int num_pieces, int piece_size)
{
FILE* f = fopen(path, "w+");
FILE* f;
if ( (f = fopen(path, "w+")) == 0)
{
fprintf(stderr, "Could not open file '%s' for writing: %s\n", path, strerror(errno));
exit(2);
}
boost::uint32_t piece[0x4000 / 4];
for (int i = 0; i < num_pieces; ++i)
@ -742,7 +748,13 @@ int main(int argc, char* argv[])
FILE* output = stdout;
if (strcmp("-", torrent_file) != 0)
output = fopen(torrent_file, "wb+");
{
if( (output = fopen(torrent_file, "wb+")) == 0)
{
fprintf(stderr, "Could not open file '%s' for writing: %s\n", torrent_file, strerror(errno));
exit(2);
}
}
fprintf(stderr, "writing file to: %s\n", torrent_file);
fwrite(&tmp[0], 1, tmp.size(), output);
if (output != stdout)
@ -791,7 +803,7 @@ int main(int argc, char* argv[])
FILE* f = fopen(torrent_name, "w+");
if (f == 0)
{
perror("open file");
fprintf(stderr, "Could not open file '%s' for writing: %s\n", torrent_name, strerror(errno));
return 1;
}
size_t ret = fwrite(&buf[0], 1, buf.size(), f);
@ -903,5 +915,3 @@ int main(int argc, char* argv[])
return 0;
}