diff --git a/ChangeLog b/ChangeLog index ee6e56a9..6dec2ee8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2009-02-13 Tatsuhiro Tsujikawa + + 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 Removed operator[] because it is ambiguous with built-in [] diff --git a/src/CookieStorage.cc b/src/CookieStorage.cc index af405285..6f384540 100644 --- a/src/CookieStorage.cc +++ b/src/CookieStorage.cc @@ -142,7 +142,7 @@ void CookieStorage::load(const std::string& filename) { 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)); if(s.bad()) { throw RecoverableException diff --git a/src/DHTSetup.cc b/src/DHTSetup.cc index 1fa70462..3673d6f1 100644 --- a/src/DHTSetup.cc +++ b/src/DHTSetup.cc @@ -96,7 +96,7 @@ void DHTSetup::setup(std::deque& commands, std::string dhtFile = option->get(PREF_DHT_FILE_PATH); if(File(dhtFile).isFile()) { try { - std::ifstream in(dhtFile.c_str()); + std::ifstream in(dhtFile.c_str(), std::ios::binary); in.exceptions(std::ios::failbit); deserializer.deserialize(in); localNode = deserializer.getLocalNode(); diff --git a/src/DHTUtil.cc b/src/DHTUtil.cc index 99cd7a7a..4118debb 100644 --- a/src/DHTUtil.cc +++ b/src/DHTUtil.cc @@ -64,7 +64,7 @@ void DHTUtil::generateRandomData(unsigned char* data, size_t length) } } #else - std::ifstream i("/dev/urandom"); + std::ifstream i("/dev/urandom", std::ios::binary); i.read(data, length); #endif // HAVE_LIBSSL } diff --git a/src/Netrc.cc b/src/Netrc.cc index c76fb80e..bb2ed705 100644 --- a/src/Netrc.cc +++ b/src/Netrc.cc @@ -78,7 +78,7 @@ void Netrc::skipMacdef(std::ifstream& f) const void Netrc::parse(const std::string& path) { authenticators.clear(); - std::ifstream f(path.c_str()); + std::ifstream f(path.c_str(), std::ios::binary); if(!f) { throw RecoverableException diff --git a/src/NsCookieParser.cc b/src/NsCookieParser.cc index 41ad22be..fece1c5a 100644 --- a/src/NsCookieParser.cc +++ b/src/NsCookieParser.cc @@ -73,7 +73,7 @@ static Cookie parseNsCookie(const std::string& nsCookieStr) std::deque NsCookieParser::parse(const std::string& filename) { - std::ifstream s(filename.c_str()); + std::ifstream s(filename.c_str(), std::ios::binary); if(!s) { throw RecoverableException (StringFormat("Failed to open file %s", filename.c_str()).str()); diff --git a/src/ProtocolDetector.cc b/src/ProtocolDetector.cc index ee743c65..9937ac03 100644 --- a/src/ProtocolDetector.cc +++ b/src/ProtocolDetector.cc @@ -55,7 +55,7 @@ bool ProtocolDetector::guessTorrentFile(const std::string& uri) const if(!File(uri).isFile()) { return false; } - std::ifstream in(uri.c_str()); + std::ifstream in(uri.c_str(), std::ios::binary); if(in) { char head; in >> head; @@ -70,7 +70,7 @@ bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const if(!File(uri).isFile()) { return false; } - std::ifstream in(uri.c_str()); + std::ifstream in(uri.c_str(), std::ios::binary); if(in) { char head[6]; in >> std::setw(6) >> head; diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index f0d7c393..f88e9a50 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -573,7 +573,7 @@ bool RequestGroupMan::addServerStat(const SharedHandle& serverStat) bool RequestGroupMan::loadServerStat(const std::string& filename) { - std::ifstream in(filename.c_str()); + std::ifstream in(filename.c_str(), std::ios::binary); if(!in) { _logger->error(MSG_OPENING_READABLE_SERVER_STAT_FILE_FAILED, filename.c_str()); return false; @@ -590,7 +590,7 @@ bool RequestGroupMan::loadServerStat(const std::string& filename) bool RequestGroupMan::saveServerStat(const std::string& filename) const { std::string tempfile = filename+"__temp"; - std::ofstream out(tempfile.c_str()); + std::ofstream out(tempfile.c_str(), std::ios::binary); if(!out) { _logger->error(MSG_OPENING_WRITABLE_SERVER_STAT_FILE_FAILED, tempfile.c_str()); diff --git a/src/Signature.cc b/src/Signature.cc index 2b3c2d4c..0062035e 100644 --- a/src/Signature.cc +++ b/src/Signature.cc @@ -77,7 +77,7 @@ bool Signature::save(const std::string& filepath) const if(File(filepath).exists()) { return false; } - std::ofstream out(filepath.c_str()); + std::ofstream out(filepath.c_str(), std::ios::binary); try { out.exceptions(std::ios::failbit); out << _body; diff --git a/src/bencode.cc b/src/bencode.cc index a635e01f..c9d70d48 100644 --- a/src/bencode.cc +++ b/src/bencode.cc @@ -439,7 +439,7 @@ BDE decode(const unsigned char* data, size_t length) 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) { return decode(f); } else { diff --git a/src/download_helper.cc b/src/download_helper.cc index 5a4e2b14..97ab72ad 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -300,7 +300,7 @@ void createRequestGroupForUriList (StringFormat(EX_FILE_OPEN, op->get(PREF_INPUT_FILE).c_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); } } diff --git a/src/option_processing.cc b/src/option_processing.cc index 4076c614..7f0eb820 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -126,7 +126,7 @@ void option_processing(Option& op, std::deque& uris, ucfname; if(File(cfname).isFile()) { - std::ifstream cfstream(cfname.c_str()); + std::ifstream cfstream(cfname.c_str(), std::ios::binary); try { oparser.parse(op, cfstream); } catch(OptionHandlerException& e) { diff --git a/test/CookieParserTest.cc b/test/CookieParserTest.cc index 816daed3..8cb8aaaa 100644 --- a/test/CookieParserTest.cc +++ b/test/CookieParserTest.cc @@ -78,7 +78,7 @@ void CookieParserTest::testParse() void CookieParserTest::testParse_file() { - std::ifstream f("cookietest.txt"); + std::ifstream f("cookietest.txt", std::ios::binary); Cookies cookies = CookieParser().parse(f); diff --git a/test/DefaultBtProgressInfoFileTest.cc b/test/DefaultBtProgressInfoFileTest.cc index c192aa30..727027f8 100644 --- a/test/DefaultBtProgressInfoFileTest.cc +++ b/test/DefaultBtProgressInfoFileTest.cc @@ -235,7 +235,7 @@ void DefaultBtProgressInfoFileTest::testSave() infoFile.save(); // read and validate - std::ifstream in(infoFile.getFilename().c_str()); + std::ifstream in(infoFile.getFilename().c_str(), std::ios::binary); //in.exceptions(ios::failbit); @@ -468,7 +468,7 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt() infoFile.save(); // read and validate - std::ifstream in(infoFile.getFilename().c_str()); + std::ifstream in(infoFile.getFilename().c_str(), std::ios::binary); //in.exceptions(ios::failbit); diff --git a/test/FileTest.cc b/test/FileTest.cc index 9cbdcef8..2b2c8d4d 100644 --- a/test/FileTest.cc +++ b/test/FileTest.cc @@ -194,7 +194,7 @@ void FileTest::testGetBasename() void FileTest::testRenameTo() { std::string fname = "FileTest_testRenameTo.txt"; - std::ofstream of(fname.c_str()); + std::ofstream of(fname.c_str(), std::ios::binary); of.close(); File f(fname); diff --git a/test/GZipDecoderTest.cc b/test/GZipDecoderTest.cc index 7b7eaf49..c42019fc 100644 --- a/test/GZipDecoderTest.cc +++ b/test/GZipDecoderTest.cc @@ -34,8 +34,8 @@ void GZipDecoderTest::testDecode() std::string outfile("/tmp/aria2_GZipDecoderTest_testDecode"); char buf[4096]; - std::ifstream in("gzip_decode_test.gz"); - std::ofstream out(outfile.c_str()); + std::ifstream in("gzip_decode_test.gz", std::ios::binary); + std::ofstream out(outfile.c_str(), std::ios::binary); while(in) { in.read(buf, sizeof(buf)); diff --git a/test/RequestGroupManTest.cc b/test/RequestGroupManTest.cc index 6f3182b5..e3e67153 100644 --- a/test/RequestGroupManTest.cc +++ b/test/RequestGroupManTest.cc @@ -93,7 +93,7 @@ void RequestGroupManTest::testSaveServerStat() void 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," << "status=OK"; o.close(); diff --git a/test/SignatureTest.cc b/test/SignatureTest.cc index e2638605..905a9a80 100644 --- a/test/SignatureTest.cc +++ b/test/SignatureTest.cc @@ -36,7 +36,7 @@ void SignatureTest::testSave() } CPPUNIT_ASSERT(sig.save(filepath)); { - std::ifstream in(filepath.c_str()); + std::ifstream in(filepath.c_str(), std::ios::binary); std::string fileContent; in >> fileContent; CPPUNIT_ASSERT_EQUAL(sig.getBody(), fileContent); diff --git a/test/SingleFileAllocationIteratorTest.cc b/test/SingleFileAllocationIteratorTest.cc index 39d2bc02..02c5e9d2 100644 --- a/test/SingleFileAllocationIteratorTest.cc +++ b/test/SingleFileAllocationIteratorTest.cc @@ -27,7 +27,7 @@ void SingleFileAllocationIteratorTest::testAllocate() std::string dir = "/tmp"; std::string fname = "aria2_SingleFileAllocationIteratorTest_testAllocate"; std::string fn = dir+"/"+fname; - std::ofstream of(fn.c_str()); + std::ofstream of(fn.c_str(), std::ios::binary); of << "0123456789"; of.close(); diff --git a/test/UriListParserTest.cc b/test/UriListParserTest.cc index 4bc38670..1234cf1c 100644 --- a/test/UriListParserTest.cc +++ b/test/UriListParserTest.cc @@ -40,7 +40,7 @@ std::string UriListParserTest::list2String(const std::deque& src) void UriListParserTest::testHasNext() { - std::ifstream in("filelist1.txt"); + std::ifstream in("filelist1.txt", std::ios::binary); UriListParser flp(in);