never write binary data to stdout on windows
This commit is contained in:
@@ -74,6 +74,10 @@ void print_usage()
|
|||||||
" than bytes will be piece-aligned\n"
|
" than bytes will be piece-aligned\n"
|
||||||
"-s bytes specifies a piece size for the torrent\n"
|
"-s bytes specifies a piece size for the torrent\n"
|
||||||
" This has to be a multiple of 16 kiB\n"
|
" This has to be a multiple of 16 kiB\n"
|
||||||
|
"-o file specifies the output filename of the torrent file\n"
|
||||||
|
" If this is not specified, the torrent file is\n"
|
||||||
|
" printed to the standard out, except on windows\n"
|
||||||
|
" where the filename defaults to a.torrent\n"
|
||||||
, stderr);
|
, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +103,13 @@ int main(int argc, char* argv[])
|
|||||||
int piece_size = 0;
|
int piece_size = 0;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
|
std::string outfile;
|
||||||
|
#ifdef TORRENT_WINDOWS
|
||||||
|
// don't ever write binary data to the console on windows
|
||||||
|
// it will just be interpreted as text and corrupted
|
||||||
|
outfile = "a.torrent";
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int i = 2; i < argc; ++i)
|
for (int i = 2; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if (argv[i][0] != '-')
|
if (argv[i][0] != '-')
|
||||||
@@ -129,6 +140,10 @@ int main(int argc, char* argv[])
|
|||||||
case 'm':
|
case 'm':
|
||||||
flags |= create_torrent::merkle;
|
flags |= create_torrent::merkle;
|
||||||
break;
|
break;
|
||||||
|
case 'o':
|
||||||
|
++i;
|
||||||
|
outfile = argv[i];
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print_usage();
|
print_usage();
|
||||||
return 1;
|
return 1;
|
||||||
@@ -170,7 +185,13 @@ int main(int argc, char* argv[])
|
|||||||
// create the torrent and print it to stdout
|
// create the torrent and print it to stdout
|
||||||
std::vector<char> torrent;
|
std::vector<char> torrent;
|
||||||
bencode(back_inserter(torrent), t.generate());
|
bencode(back_inserter(torrent), t.generate());
|
||||||
fwrite(&torrent[0], 1, torrent.size(), stdout);
|
FILE* output = stdout;
|
||||||
|
if (!outfile.empty())
|
||||||
|
output = fopen(outfile.c_str(), "wb+");
|
||||||
|
fwrite(&torrent[0], 1, torrent.size(), output);
|
||||||
|
|
||||||
|
if (output != stdout)
|
||||||
|
fclose(output);
|
||||||
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user