octave-maintainers
[Top][All Lists]
Advanced

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

RE: Octave + ZLIB + Win32


From: John W. Eaton
Subject: RE: Octave + ZLIB + Win32
Date: Wed, 7 Feb 2007 02:27:05 -0500

On  8-Dec-2006, address@hidden wrote:

| > 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;
|   }

I see no reason to make this conditional, so I just checked in the
attached change.

Thanks,

jwe

src/ChangeLog:

2007-02-07  John W. Eaton  <address@hidden>

        * zfstream.cc (gzfilebuf::open_mode): Always append "b" to c_mode.


Index: src/zfstream.cc
===================================================================
RCS file: /cvs/octave/src/zfstream.cc,v
retrieving revision 1.2
diff -u -u -r1.2 zfstream.cc
--- src/zfstream.cc     26 Apr 2005 19:24:35 -0000      1.2
+++ src/zfstream.cc     7 Feb 2007 07:26:30 -0000
@@ -187,8 +187,9 @@
   // Mode string should be empty for invalid combination of flags
   if (strlen(c_mode) == 0)
     return false;
-  if (testb)
-    strcat(c_mode, "b");
+
+  strcat(c_mode, "b");
+
   return true;
 }
 

reply via email to

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