Browse Source

Better handling SQFile Tell/Len

mingodad 5 years ago
parent
commit
7a02f797ac
3 changed files with 3 additions and 2 deletions
  1. 1 0
      SquiLu/include/squirrel.h
  2. 2 1
      SquiLu/sqstdlib/sqstdfile.h
  3. 0 1
      SquiLu/sqstdlib/sqstdmath.cpp

+ 1 - 0
SquiLu/include/squirrel.h

@@ -29,6 +29,7 @@ extern "C" {
 
 #include <stdarg.h>
 #include <stdint.h>
+#include <limits.h>
 
 #ifndef SQUIRREL_API
 #define SQUIRREL_API extern //__attribute__ ((visibility ("default")))

+ 2 - 1
SquiLu/sqstdlib/sqstdfile.h

@@ -36,7 +36,8 @@ struct SQFile : public SQStream {
 		return sqstd_fflush(_handle);
 	}
 	SQInteger Tell() {
-		return sqstd_ftell(_handle);
+		SQInteger pos = sqstd_ftell(_handle);
+		return pos == SQ_INT_MAX ? 0 : (pos > 0 ? pos : 0);
 	}
 	SQInteger Len() {
 		SQInteger prevpos=Tell();

+ 0 - 1
SquiLu/sqstdlib/sqstdmath.cpp

@@ -2,7 +2,6 @@
 #include <squirrel.h>
 #include <math.h>
 //#include <float.h>
-#include <limits.h>
 #include <stdlib.h>
 #include <sqstdmath.h>