|
@@ -59,6 +59,7 @@ using namespace std;
|
|
|
#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 @@ AMI_err AMI_STREAM<T>::new_substream(AMI_stream_type st,
|
|
|
//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 @@ AMI_err AMI_STREAM<T>::new_substream(AMI_stream_type st,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#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 @@ off_t AMI_STREAM<T>::stream_len(void) {
|
|
|
|
|
|
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 @@ off_t AMI_STREAM<T>::stream_len(void) {
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|