]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/sg_file.cxx
Use the new SGPath::create_dir function
[simgear.git] / simgear / io / sg_file.cxx
index cd7fa1d5b558ee0282eccd37bd572d3ae30c89bb..dace6454060c5e7bad2b100587f0ef2e6e3f84ab 100644 (file)
@@ -29,6 +29,7 @@
 #  include <io.h>
 #endif
 
+#include <simgear/misc/stdint.hxx>
 #include <simgear/debug/logstream.hxx>
 
 #include "sg_file.hxx"
@@ -39,6 +40,7 @@ SG_USING_STD(string);
 SGFile::SGFile( const string &file) {
     set_type( sgFileType );
     file_name = file;
+    eof_flag = true;
 }
 
 
@@ -70,6 +72,7 @@ bool SGFile::open( const SGProtocolDir d ) {
        return false;
     }
 
+    eof_flag = false;
     return true;
 }
 
@@ -77,7 +80,11 @@ bool SGFile::open( const SGProtocolDir d ) {
 // read a block of data of specified size
 int SGFile::read( char *buf, int length ) {
     // read a chunk
-    return ::read( fp, buf, length );
+    ssize_t result = ::read( fp, buf, length );
+    if ( length > 0 && result == 0 ) {
+        eof_flag = true;
+    }
+    return result;
 }
 
 
@@ -87,7 +94,10 @@ int SGFile::readline( char *buf, int length ) {
     int pos = lseek( fp, 0, SEEK_CUR );
 
     // read a chunk
-    int result = ::read( fp, buf, length );
+    ssize_t result = ::read( fp, buf, length );
+    if ( length > 0 && result == 0 ) {
+        eof_flag = true;
+    }
 
     // find the end of line and reset position
     int i;
@@ -130,5 +140,6 @@ bool SGFile::close() {
        return false;
     }
 
+    eof_flag = true;
     return true;
 }