- int64_t to_read = amount - read;
-#ifdef DCPOMATIC_WINDOWS
- /* If we over-read from the file by too much on Windows we get a errno=22 rather than an feof condition,
- * for unknown reasons. So if we're going to over-read, we need to do it by a little bit, so that feof
- * still gets triggered but there is no errno=22.
- */
- to_read = std::min(to_read, static_cast<int64_t>(_current_size - _ftelli64(_current_file) + 1));
-#endif
- int const this_time = fread (buffer + read, 1, to_read, _current_file);
+
+ bool eof = false;
+ size_t to_read = amount - read;
+
+ DCPOMATIC_ASSERT (_current_file);
+
+ auto const current_position = _current_file->tell();
+ 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;
+ }
+
+ int const this_time = _current_file->read(buffer + read, 1, to_read);