diff libinterp/corefcn/ls-mat-ascii.cc @ 17183:ca5103ab0b21

check_gzip_magic before get_file_format (wrong type detection, bug #39652) * load-save.cc (get_file_format): call check_gzip_magic before get_file_format to avoid random LS_MAT_ASCII detections in gzipped files. * ls-mat-ascii.cc (looks_like_mat_ascii_file): New arg, IS which could also be a gzipped file, is now opened in the calling function. * ls-mat-ascii.h (looks_like_mat_ascii_file): New arg, IS.
author Andreas Weber <andy.weber.aw@gmail.com>
date Fri, 02 Aug 2013 19:48:34 +0200
parents 68fc671a9339
children d63878346099
line wrap: on
line diff
--- a/libinterp/corefcn/ls-mat-ascii.cc	Mon Aug 05 11:43:58 2013 -0700
+++ b/libinterp/corefcn/ls-mat-ascii.cc	Fri Aug 02 19:48:34 2013 +0200
@@ -107,7 +107,7 @@
 }
 
 static void
-get_lines_and_columns (std::istream& is, 
+get_lines_and_columns (std::istream& is,
                        octave_idx_type& nr, octave_idx_type& nc,
                        const std::string& filename = std::string (),
                        bool quiet = false, bool check_numeric = false)
@@ -410,21 +410,14 @@
 }
 
 bool
-looks_like_mat_ascii_file (const std::string& filename)
+looks_like_mat_ascii_file (std::istream& is, const std::string& filename)
 {
   bool retval = false;
-
-  std::ifstream is (filename.c_str ());
+  octave_idx_type nr = 0;
+  octave_idx_type nc = 0;
 
-  if (is)
-    {
-      octave_idx_type nr = 0;
-      octave_idx_type nc = 0;
-
-      get_lines_and_columns (is, nr, nc, filename, true, true);
-
-      retval = (nr != 0 && nc != 0);
-    }
+  get_lines_and_columns (is, nr, nc, filename, true, true);
+  retval = (nr != 0 && nc != 0);
 
   return retval;
 }