octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Octave + ZLIB + Win32


From: michael . goffioul
Subject: RE: Octave + ZLIB + Win32
Date: Fri, 08 Dec 2006 11:25:10 +0100

> I suspect you need to use "wb" here. The zlib.h header says
> ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
 
Thanks. As you and Paul suggested, the problem is the text/binary mode
for opening the file. I thought that the text mode (with 't' suffix) was only
enabled if explicitely specified, but it is the default; hence MSVC translates
'\\n' into '\\r\\n' and corrupts the compressed data. So, under MSVC, you
really need to specify 'b' explicitely.
 
> Strange that they would allow these other extensions to the mode
> string and not automatically open the stream in binary mode (since it
> would seem to be required) whether or not "b" is specified.
> Is Octave failing to open a stream in binary mode when it should?

When saving in compressed text form, the gzFile stream is opened without
the 'b' suffix (mode does not contain std::ios::binary). I proposed the following
patch, which forces binary mode on compressed streams under Win32
except Cygwin.
 
Michael.
 
Index: src/zfstream.cc
===================================================================
RCS file: /cvs/octave/src/zfstream.cc,v
retrieving revision 1.2
diff -c -p -r1.2 zfstream.cc
*** src/zfstream.cc     26 Apr 2005 19:24:35 -0000      1.2
--- src/zfstream.cc     8 Dec 2006 10:24:49 -0000
*************** gzfilebuf::open_mode(std::ios_base::open
*** 187,193 ****
--- 187,195 ----
    // Mode string should be empty for invalid combination of flags
    if (strlen(c_mode) == 0)
      return false;
+ #if ! defined (__WIN32__) || defined (__CYGWIN__)
    if (testb)
+ #endif
      strcat(c_mode, "b");
    return true;
  }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]