2009-02-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Open file in binary mode.
	* src/CookieStorage.cc
	* src/DHTSetup.cc
	* src/DHTUtil.cc
	* src/Netrc.cc
	* src/NsCookieParser.cc
	* src/ProtocolDetector.cc
	* src/RequestGroupMan.cc
	* src/Signature.cc
	* src/bencode.cc
	* src/download_helper.cc
	* src/option_processing.cc
	* test/CookieParserTest.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/FileTest.cc
	* test/GZipDecoderTest.cc
	* test/RequestGroupManTest.cc
	* test/SignatureTest.cc
	* test/SingleFileAllocationIteratorTest.cc
	* test/UriListParserTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-02-13 11:28:42 +00:00
parent 9d27eb53f5
commit 34d7cd7a70
20 changed files with 46 additions and 23 deletions

View File

@ -1,3 +1,26 @@
2009-02-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Open file in binary mode.
* src/CookieStorage.cc
* src/DHTSetup.cc
* src/DHTUtil.cc
* src/Netrc.cc
* src/NsCookieParser.cc
* src/ProtocolDetector.cc
* src/RequestGroupMan.cc
* src/Signature.cc
* src/bencode.cc
* src/download_helper.cc
* src/option_processing.cc
* test/CookieParserTest.cc
* test/DefaultBtProgressInfoFileTest.cc
* test/FileTest.cc
* test/GZipDecoderTest.cc
* test/RequestGroupManTest.cc
* test/SignatureTest.cc
* test/SingleFileAllocationIteratorTest.cc
* test/UriListParserTest.cc
2009-02-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-02-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed operator[] because it is ambiguous with built-in [] Removed operator[] because it is ambiguous with built-in []

View File

@ -142,7 +142,7 @@ void CookieStorage::load(const std::string& filename)
{ {
char header[16]; // "SQLite format 3" plus \0 char header[16]; // "SQLite format 3" plus \0
{ {
std::ifstream s(filename.c_str()); std::ifstream s(filename.c_str(), std::ios::binary);
s.get(header, sizeof(header)); s.get(header, sizeof(header));
if(s.bad()) { if(s.bad()) {
throw RecoverableException throw RecoverableException

View File

@ -96,7 +96,7 @@ void DHTSetup::setup(std::deque<Command*>& commands,
std::string dhtFile = option->get(PREF_DHT_FILE_PATH); std::string dhtFile = option->get(PREF_DHT_FILE_PATH);
if(File(dhtFile).isFile()) { if(File(dhtFile).isFile()) {
try { try {
std::ifstream in(dhtFile.c_str()); std::ifstream in(dhtFile.c_str(), std::ios::binary);
in.exceptions(std::ios::failbit); in.exceptions(std::ios::failbit);
deserializer.deserialize(in); deserializer.deserialize(in);
localNode = deserializer.getLocalNode(); localNode = deserializer.getLocalNode();

View File

@ -64,7 +64,7 @@ void DHTUtil::generateRandomData(unsigned char* data, size_t length)
} }
} }
#else #else
std::ifstream i("/dev/urandom"); std::ifstream i("/dev/urandom", std::ios::binary);
i.read(data, length); i.read(data, length);
#endif // HAVE_LIBSSL #endif // HAVE_LIBSSL
} }

View File

@ -78,7 +78,7 @@ void Netrc::skipMacdef(std::ifstream& f) const
void Netrc::parse(const std::string& path) void Netrc::parse(const std::string& path)
{ {
authenticators.clear(); authenticators.clear();
std::ifstream f(path.c_str()); std::ifstream f(path.c_str(), std::ios::binary);
if(!f) { if(!f) {
throw RecoverableException throw RecoverableException

View File

@ -73,7 +73,7 @@ static Cookie parseNsCookie(const std::string& nsCookieStr)
std::deque<Cookie> NsCookieParser::parse(const std::string& filename) std::deque<Cookie> NsCookieParser::parse(const std::string& filename)
{ {
std::ifstream s(filename.c_str()); std::ifstream s(filename.c_str(), std::ios::binary);
if(!s) { if(!s) {
throw RecoverableException throw RecoverableException
(StringFormat("Failed to open file %s", filename.c_str()).str()); (StringFormat("Failed to open file %s", filename.c_str()).str());

View File

@ -55,7 +55,7 @@ bool ProtocolDetector::guessTorrentFile(const std::string& uri) const
if(!File(uri).isFile()) { if(!File(uri).isFile()) {
return false; return false;
} }
std::ifstream in(uri.c_str()); std::ifstream in(uri.c_str(), std::ios::binary);
if(in) { if(in) {
char head; char head;
in >> head; in >> head;
@ -70,7 +70,7 @@ bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const
if(!File(uri).isFile()) { if(!File(uri).isFile()) {
return false; return false;
} }
std::ifstream in(uri.c_str()); std::ifstream in(uri.c_str(), std::ios::binary);
if(in) { if(in) {
char head[6]; char head[6];
in >> std::setw(6) >> head; in >> std::setw(6) >> head;

View File

@ -573,7 +573,7 @@ bool RequestGroupMan::addServerStat(const SharedHandle<ServerStat>& serverStat)
bool RequestGroupMan::loadServerStat(const std::string& filename) bool RequestGroupMan::loadServerStat(const std::string& filename)
{ {
std::ifstream in(filename.c_str()); std::ifstream in(filename.c_str(), std::ios::binary);
if(!in) { if(!in) {
_logger->error(MSG_OPENING_READABLE_SERVER_STAT_FILE_FAILED, filename.c_str()); _logger->error(MSG_OPENING_READABLE_SERVER_STAT_FILE_FAILED, filename.c_str());
return false; return false;
@ -590,7 +590,7 @@ bool RequestGroupMan::loadServerStat(const std::string& filename)
bool RequestGroupMan::saveServerStat(const std::string& filename) const bool RequestGroupMan::saveServerStat(const std::string& filename) const
{ {
std::string tempfile = filename+"__temp"; std::string tempfile = filename+"__temp";
std::ofstream out(tempfile.c_str()); std::ofstream out(tempfile.c_str(), std::ios::binary);
if(!out) { if(!out) {
_logger->error(MSG_OPENING_WRITABLE_SERVER_STAT_FILE_FAILED, _logger->error(MSG_OPENING_WRITABLE_SERVER_STAT_FILE_FAILED,
tempfile.c_str()); tempfile.c_str());

View File

@ -77,7 +77,7 @@ bool Signature::save(const std::string& filepath) const
if(File(filepath).exists()) { if(File(filepath).exists()) {
return false; return false;
} }
std::ofstream out(filepath.c_str()); std::ofstream out(filepath.c_str(), std::ios::binary);
try { try {
out.exceptions(std::ios::failbit); out.exceptions(std::ios::failbit);
out << _body; out << _body;

View File

@ -439,7 +439,7 @@ BDE decode(const unsigned char* data, size_t length) throw(RecoverableException)
BDE decodeFromFile(const std::string& filename) throw(RecoverableException) BDE decodeFromFile(const std::string& filename) throw(RecoverableException)
{ {
std::ifstream f(filename.c_str()); std::ifstream f(filename.c_str(), std::ios::binary);
if(f) { if(f) {
return decode(f); return decode(f);
} else { } else {

View File

@ -300,7 +300,7 @@ void createRequestGroupForUriList
(StringFormat(EX_FILE_OPEN, op->get(PREF_INPUT_FILE).c_str(), (StringFormat(EX_FILE_OPEN, op->get(PREF_INPUT_FILE).c_str(),
"No such file").str()); "No such file").str());
} }
std::ifstream f(op->get(PREF_INPUT_FILE).c_str()); std::ifstream f(op->get(PREF_INPUT_FILE).c_str(), std::ios::binary);
createRequestGroupForUriList(result, op, f); createRequestGroupForUriList(result, op, f);
} }
} }

View File

@ -126,7 +126,7 @@ void option_processing(Option& op, std::deque<std::string>& uris,
ucfname; ucfname;
if(File(cfname).isFile()) { if(File(cfname).isFile()) {
std::ifstream cfstream(cfname.c_str()); std::ifstream cfstream(cfname.c_str(), std::ios::binary);
try { try {
oparser.parse(op, cfstream); oparser.parse(op, cfstream);
} catch(OptionHandlerException& e) { } catch(OptionHandlerException& e) {

View File

@ -78,7 +78,7 @@ void CookieParserTest::testParse()
void CookieParserTest::testParse_file() void CookieParserTest::testParse_file()
{ {
std::ifstream f("cookietest.txt"); std::ifstream f("cookietest.txt", std::ios::binary);
Cookies cookies = CookieParser().parse(f); Cookies cookies = CookieParser().parse(f);

View File

@ -235,7 +235,7 @@ void DefaultBtProgressInfoFileTest::testSave()
infoFile.save(); infoFile.save();
// read and validate // read and validate
std::ifstream in(infoFile.getFilename().c_str()); std::ifstream in(infoFile.getFilename().c_str(), std::ios::binary);
//in.exceptions(ios::failbit); //in.exceptions(ios::failbit);
@ -468,7 +468,7 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
infoFile.save(); infoFile.save();
// read and validate // read and validate
std::ifstream in(infoFile.getFilename().c_str()); std::ifstream in(infoFile.getFilename().c_str(), std::ios::binary);
//in.exceptions(ios::failbit); //in.exceptions(ios::failbit);

View File

@ -194,7 +194,7 @@ void FileTest::testGetBasename()
void FileTest::testRenameTo() void FileTest::testRenameTo()
{ {
std::string fname = "FileTest_testRenameTo.txt"; std::string fname = "FileTest_testRenameTo.txt";
std::ofstream of(fname.c_str()); std::ofstream of(fname.c_str(), std::ios::binary);
of.close(); of.close();
File f(fname); File f(fname);

View File

@ -34,8 +34,8 @@ void GZipDecoderTest::testDecode()
std::string outfile("/tmp/aria2_GZipDecoderTest_testDecode"); std::string outfile("/tmp/aria2_GZipDecoderTest_testDecode");
char buf[4096]; char buf[4096];
std::ifstream in("gzip_decode_test.gz"); std::ifstream in("gzip_decode_test.gz", std::ios::binary);
std::ofstream out(outfile.c_str()); std::ofstream out(outfile.c_str(), std::ios::binary);
while(in) { while(in) {
in.read(buf, sizeof(buf)); in.read(buf, sizeof(buf));

View File

@ -93,7 +93,7 @@ void RequestGroupManTest::testSaveServerStat()
void RequestGroupManTest::testLoadServerStat() void RequestGroupManTest::testLoadServerStat()
{ {
File f("/tmp/aria2_RequestGroupManTest_testLoadServerStat"); File f("/tmp/aria2_RequestGroupManTest_testLoadServerStat");
std::ofstream o(f.getPath().c_str()); std::ofstream o(f.getPath().c_str(), std::ios::binary);
o << "host=localhost, protocol=http, dl_speed=0, last_updated=1219505257," o << "host=localhost, protocol=http, dl_speed=0, last_updated=1219505257,"
<< "status=OK"; << "status=OK";
o.close(); o.close();

View File

@ -36,7 +36,7 @@ void SignatureTest::testSave()
} }
CPPUNIT_ASSERT(sig.save(filepath)); CPPUNIT_ASSERT(sig.save(filepath));
{ {
std::ifstream in(filepath.c_str()); std::ifstream in(filepath.c_str(), std::ios::binary);
std::string fileContent; std::string fileContent;
in >> fileContent; in >> fileContent;
CPPUNIT_ASSERT_EQUAL(sig.getBody(), fileContent); CPPUNIT_ASSERT_EQUAL(sig.getBody(), fileContent);

View File

@ -27,7 +27,7 @@ void SingleFileAllocationIteratorTest::testAllocate()
std::string dir = "/tmp"; std::string dir = "/tmp";
std::string fname = "aria2_SingleFileAllocationIteratorTest_testAllocate"; std::string fname = "aria2_SingleFileAllocationIteratorTest_testAllocate";
std::string fn = dir+"/"+fname; std::string fn = dir+"/"+fname;
std::ofstream of(fn.c_str()); std::ofstream of(fn.c_str(), std::ios::binary);
of << "0123456789"; of << "0123456789";
of.close(); of.close();

View File

@ -40,7 +40,7 @@ std::string UriListParserTest::list2String(const std::deque<std::string>& src)
void UriListParserTest::testHasNext() void UriListParserTest::testHasNext()
{ {
std::ifstream in("filelist1.txt"); std::ifstream in("filelist1.txt", std::ios::binary);
UriListParser flp(in); UriListParser flp(in);