[GRASS-SVN] r42806 - grass/trunk/include/iostream

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 16 06:17:48 EDT 2010


Author: mmetz
Date: 2010-07-16 10:17:48 +0000 (Fri, 16 Jul 2010)
New Revision: 42806

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

Modified: grass/trunk/include/iostream/ami_stream.h
===================================================================
--- grass/trunk/include/iostream/ami_stream.h	2010-07-16 10:17:14 UTC (rev 42805)
+++ grass/trunk/include/iostream/ami_stream.h	2010-07-16 10:17:48 UTC (rev 42806)
@@ -59,6 +59,7 @@
 #include "mm.h" // Get the memory manager.
 
 #define DEBUG_DELETE if(0)
+#define DEBUG_STREAM_LEN if(0)
 
 // The name of the environment variable which keeps the name of the
 // directory where streams are stored
@@ -320,6 +321,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)) ||
@@ -335,9 +342,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;
@@ -371,6 +380,30 @@
 
   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);
+
+#else
   struct stat buf;
   if (stat(path, &buf) == -1) {
     perror("AMI_STREAM::stream_len(): fstat failed ");
@@ -378,10 +411,22 @@
     assert(0);
     exit(1);
   }
+#endif
 
-  //fprintf(stderr, "%s: length = %lld\n", path, buf.st_size);
 
+#ifdef __MINGW32__
+  //debug stream_len:
+  DEBUG_STREAM_LEN fprintf(stderr, "%s: length = %lld   sizeof(T)=%d\n",
+	  path, st_size, sizeof(T));
+
+  return (st_size / sizeof(T));
+#else
+  //debug stream_len:
+  DEBUG_STREAM_LEN fprintf(stderr, "%s: length = %lld   sizeof(T)=%d\n",
+	  path, buf.st_size, sizeof(T));
+
   return (buf.st_size / sizeof(T));
+#endif
 };
 
 



More information about the grass-commit mailing list