[Botan-devel] [PATCH] Open fstreams in binary mode where appropriate.

Matthew Gregan kinetik at orcon.net.nz
Sun Aug 7 03:18:03 EDT 2005


Hello,

Please find attached a patch to ensure files that are assumed to be
binary streams are opened using the ios::binary flag, to avoid EOF
translation on platforms such as Win32.

The testsuite passes on Linux and Win32 (MinGW) before and after making
these changes.

Cheers,
-mjg
-- 
Matthew Gregan                     |/
                                  /|                kinetik at orcon.net.nz
-------------- next part --------------
diff -BNru Botan-1.4.6/modules/es_ftw/es_ftw.cpp Botan-1.4.6-bin/modules/es_ftw/es_ftw.cpp
--- Botan-1.4.6/modules/es_ftw/es_ftw.cpp	2005-03-14 13:31:05.000000000 +1300
+++ Botan-1.4.6-bin/modules/es_ftw/es_ftw.cpp	2005-08-07 18:56:40.000000000 +1200
@@ -88,7 +88,7 @@
 *************************************************/
 void FTW_EntropySource::gather_from_file(const std::string& filename)
    {
-   std::ifstream in(filename.c_str());
+   std::ifstream in(filename.c_str(), std::ios::binary);
    if(!in) return;
 
    SecureVector<byte> read_buf(1024);
diff -BNru Botan-1.4.6/src/data_snk.cpp Botan-1.4.6-bin/src/data_snk.cpp
--- Botan-1.4.6/src/data_snk.cpp	2005-03-14 13:31:04.000000000 +1300
+++ Botan-1.4.6-bin/src/data_snk.cpp	2005-08-07 18:56:40.000000000 +1200
@@ -32,7 +32,7 @@
 *************************************************/
 DataSink_Stream::DataSink_Stream(const std::string& file) : fsname(file)
    {
-   sink = new std::ofstream(fsname.c_str());
+   sink = new std::ofstream(fsname.c_str(), std::ios::binary);
    if(!sink->good())
       throw Stream_IO_Error("DataSink_Stream: Failure opening " + fsname);
    owns = true;
diff -BNru Botan-1.4.6/src/data_src.cpp Botan-1.4.6-bin/src/data_src.cpp
--- Botan-1.4.6/src/data_src.cpp	2005-03-14 13:31:04.000000000 +1300
+++ Botan-1.4.6-bin/src/data_src.cpp	2005-08-07 18:56:40.000000000 +1200
@@ -156,7 +156,7 @@
 *************************************************/
 DataSource_Stream::DataSource_Stream(const std::string& file) : fsname(file)
    {
-   source = new std::ifstream(fsname.c_str());
+   source = new std::ifstream(fsname.c_str(), std::ios::binary);
    if(!source->good())
       throw Stream_IO_Error("DataSource_Stream: Failure opening " + fsname);
    total_read = 0;
diff -BNru Botan-1.4.6/src/es_file.cpp Botan-1.4.6-bin/src/es_file.cpp
--- Botan-1.4.6/src/es_file.cpp	2005-03-14 13:31:04.000000000 +1300
+++ Botan-1.4.6-bin/src/es_file.cpp	2005-08-07 18:56:40.000000000 +1200
@@ -39,7 +39,7 @@
    u32bit read = 0;
    for(u32bit j = 0; j != sources.size(); j++)
       {
-      std::ifstream random_source(sources[j].c_str());
+      std::ifstream random_source(sources[j].c_str(), std::ios::binary);
       if(!random_source) continue;
       random_source.read((char*)output + read, length);
       read += random_source.gcount();


More information about the botan-devel mailing list