[GRASS-SVN] r42716 - grass/branches/develbranch_6/include/iostream

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 8 06:18:29 EDT 2010


Author: hamish
Date: 2010-07-08 10:18:29 +0000 (Thu, 08 Jul 2010)
New Revision: 42716

Modified:
   grass/branches/develbranch_6/include/iostream/ami_stream.h
Log:
apply patch from #1006 to avoid using stat() on open files on MS Windows

Modified: grass/branches/develbranch_6/include/iostream/ami_stream.h
===================================================================
--- grass/branches/develbranch_6/include/iostream/ami_stream.h	2010-07-08 10:12:10 UTC (rev 42715)
+++ grass/branches/develbranch_6/include/iostream/ami_stream.h	2010-07-08 10:18:29 UTC (rev 42716)
@@ -353,6 +353,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 ");
@@ -360,12 +384,22 @@
     assert(0);
     exit(1);
   }
+#endif
 
-  //DEBUG:
+
+#ifdef __MINGW32__
+  //TEMPORARY DEBUG:
   fprintf(stderr, "%s: length = %lld   sizeof(T)=%d\n",
+	  path, st_size, sizeof(T));
+
+  return (st_size / sizeof(T));
+#else
+  //TEMPORARY DEBUG:
+  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