- int const this_time = fread (buffer + read, 1, amount - read, _current_file);
+
+ bool eof = false;
+ size_t to_read = amount - read;
+
+ DCPOMATIC_ASSERT (_current_file);
+
+#ifdef DCPOMATIC_WINDOWS
+ int64_t const current_position = _ftelli64 (_current_file);
+ if (current_position == -1) {
+ to_read = 0;
+ eof = true;
+ } else if ((current_position + to_read) > _current_size) {
+ to_read = _current_size - current_position;
+ eof = true;
+ }
+#else
+ long const current_position = ftell(_current_file);
+ if ((current_position + to_read) > _current_size) {
+ to_read = _current_size - current_position;
+ eof = true;
+ }
+#endif
+
+ int const this_time = fread (buffer + read, 1, to_read, _current_file);