changeset 28993:cc287e633588 stable

Always open files in binary mode for saving variables (bug #59238). * load-save.cc (load_save_system::save): Open ofstream in binary mode for all save file formats. This means that line endings are stored as-is and are no longer converted dependent on the platform. * ls-ascii-helper.cc: Add comment as a reminder to keep these functions even though we no longer save variables in files in text mode.
author Markus Mützel <markus.muetzel@gmx.de>
date Fri, 23 Oct 2020 18:59:29 +0200
parents d08d55570a98
children c3970f97f9b8 55bdcab3d85b
files libinterp/corefcn/load-save.cc libinterp/corefcn/ls-ascii-helper.cc
diffstat 2 files changed, 7 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/load-save.cc	Sat Oct 24 11:17:46 2020 -0400
+++ b/libinterp/corefcn/load-save.cc	Fri Oct 23 18:59:29 2020 +0200
@@ -1471,14 +1471,8 @@
         std::ios::openmode mode
           = (append ? (std::ios::app | std::ios::ate) : std::ios::out);
 
-        if (format.type () == BINARY
-#if defined (HAVE_HDF5)
-            || format.type () == HDF5
-#endif
-            || format.type () == MAT_BINARY
-            || format.type () == MAT5_BINARY
-            || format.type () == MAT7_BINARY)
-          mode |= std::ios::binary;
+        // Always open in binary mode to save line endings as is.
+        mode |= std::ios::binary;
 
 #if defined (HAVE_HDF5)
         if (format.type () == HDF5)
--- a/libinterp/corefcn/ls-ascii-helper.cc	Sat Oct 24 11:17:46 2020 -0400
+++ b/libinterp/corefcn/ls-ascii-helper.cc	Fri Oct 23 18:59:29 2020 +0200
@@ -34,8 +34,11 @@
 
 // Helper functions when reading from ascii files.
 
-// These function take care of CR/LF issues when files are opened in
-// text-mode for reading.
+// These functions take care of different line endings (LF, CR, CRLF)
+// when files were opened in text mode for writing and are now opened in
+// binary mode for reading.
+// Even though we no longer store files in text mode, keep this logic
+// to allow loading older files that might have CRLF or CR line endings.
 
 // Skip characters from stream IS until a newline is reached.
 // Depending on KEEP_NEWLINE, either eat newline from stream or