[GRASS-SVN] r42807 - grass/branches/releasebranch_6_4/include/iostream

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 16 06:46:08 EDT 2010


Author: mmetz
Date: 2010-07-16 10:46:08 +0000 (Fri, 16 Jul 2010)
New Revision: 42807

Modified:
   grass/branches/releasebranch_6_4/include/iostream/ami_stream.h
Log:
iostream: backport fix for #1006 from devbr

Modified: grass/branches/releasebranch_6_4/include/iostream/ami_stream.h
===================================================================
--- grass/branches/releasebranch_6_4/include/iostream/ami_stream.h	2010-07-16 10:17:48 UTC (rev 42806)
+++ grass/branches/releasebranch_6_4/include/iostream/ami_stream.h	2010-07-16 10:46:08 UTC (rev 42807)
@@ -302,6 +302,12 @@
   //assume this for now
   assert(st == AMI_READ_STREAM);
 
+#ifdef __MINGW32__
+  /* MINGW32: reopen file here for stream_len() below */
+  //reopen the file 
+  AMI_STREAM<T> *substr = new AMI_STREAM<T>(path, st);
+#endif
+
   //check range
   if (substream_level) {
      if( (sub_begin >= (logical_eos - logical_bos)) ||
@@ -317,9 +323,11 @@
     }
   }
 
+#ifndef __MINGW32__
   //reopen the file 
   AMI_STREAM<T> *substr = new AMI_STREAM<T>(path, st);
-  
+#endif
+
   // Set up the beginning and end positions.
   if (substream_level) {
     substr->logical_bos = logical_bos + sub_begin;
@@ -353,6 +361,31 @@
 
   fflush(fp);
 
+#ifdef __MINGW32__
+  //stat() fails on MS Windows if the file is open, so try ftell() instead.
+  //FIXME: not 64bit safe, but WinGrass isn't either right now.
+  //try something with #ifdef HAVE_LARGEFILES ? (see fseeko() elsewhere in this file)
+  long posn_save, st_size;
+
+  posn_save = ftell(fp);
+  if(posn_save == -1) {
+     perror("ERROR: AMI_STREAM::stream_len(): ftell(fp) failed ");
+     perror(path);
+     exit(1);
+  }
+
+  fseek(fp, 0, SEEK_END);
+  st_size = ftell(fp);
+  if(st_size == -1) {
+     perror("ERROR: AMI_STREAM::stream_len(): ftell[SEEK_END] failed ");
+     perror(path);
+     exit(1);
+  }
+
+  fseek(fp, posn_save, SEEK_SET);
+  return (st_size / sizeof(T));
+
+#else
   struct stat buf;
   if (stat(path, &buf) == -1) {
     perror("AMI_STREAM::stream_len(): fstat failed ");
@@ -360,10 +393,8 @@
     assert(0);
     exit(1);
   }
-
-  //fprintf(stderr, "%s: length = %lld\n", path, buf.st_size);
-
   return (buf.st_size / sizeof(T));
+#endif
 };
 
 



More information about the grass-commit mailing list