UWP VFS: Calculate buffer offset correctly when read fails due to EOF
This commit is contained in:
parent
c209b0b3d9
commit
5faf6a124d
|
@ -1198,7 +1198,7 @@ void fill_pathname_home_dir(char *s, size_t len)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool is_path_accessible_using_standard_io(char *path)
|
bool is_path_accessible_using_standard_io(const char *path)
|
||||||
{
|
{
|
||||||
#ifdef __WINRT__
|
#ifdef __WINRT__
|
||||||
bool result;
|
bool result;
|
||||||
|
|
|
@ -498,7 +498,7 @@ bool path_is_valid(const char *path);
|
||||||
|
|
||||||
int32_t path_get_size(const char *path);
|
int32_t path_get_size(const char *path);
|
||||||
|
|
||||||
bool is_path_accessible_using_standard_io(char *path);
|
bool is_path_accessible_using_standard_io(const char *path);
|
||||||
|
|
||||||
RETRO_END_DECLS
|
RETRO_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -340,7 +340,7 @@ struct libretro_vfs_implementation_file
|
||||||
char* orig_path;
|
char* orig_path;
|
||||||
size_t buffer_size;
|
size_t buffer_size;
|
||||||
int buffer_left;
|
int buffer_left;
|
||||||
|
size_t buffer_fill;
|
||||||
};
|
};
|
||||||
|
|
||||||
libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints)
|
libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints)
|
||||||
|
@ -401,6 +401,7 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, uns
|
||||||
stream->buffer = (char*)malloc(buf_size);
|
stream->buffer = (char*)malloc(buf_size);
|
||||||
stream->bufferp = CreateNativeBuffer(stream->buffer, buf_size, 0);
|
stream->bufferp = CreateNativeBuffer(stream->buffer, buf_size, 0);
|
||||||
stream->buffer_left = 0;
|
stream->buffer_left = 0;
|
||||||
|
stream->buffer_fill = 0;
|
||||||
stream->buffer_size = buf_size;
|
stream->buffer_size = buf_size;
|
||||||
return stream;
|
return stream;
|
||||||
});
|
});
|
||||||
|
@ -484,7 +485,7 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void
|
||||||
// Small read, use manually buffered IO
|
// Small read, use manually buffered IO
|
||||||
if (stream->buffer_left < len) {
|
if (stream->buffer_left < len) {
|
||||||
// Exhaust the buffer
|
// Exhaust the buffer
|
||||||
memcpy(s, &stream->buffer[stream->buffer_size - stream->buffer_left], stream->buffer_left);
|
memcpy(s, &stream->buffer[stream->buffer_fill - stream->buffer_left], stream->buffer_left);
|
||||||
len -= stream->buffer_left;
|
len -= stream->buffer_left;
|
||||||
bytes_read += stream->buffer_left;
|
bytes_read += stream->buffer_left;
|
||||||
stream->buffer_left = 0;
|
stream->buffer_left = 0;
|
||||||
|
@ -496,9 +497,11 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void
|
||||||
return (int64_t)stream->bufferp->Length;
|
return (int64_t)stream->bufferp->Length;
|
||||||
});
|
});
|
||||||
}, -1);
|
}, -1);
|
||||||
|
stream->buffer_fill = stream->buffer_left;
|
||||||
|
|
||||||
if (stream->buffer_left == -1) {
|
if (stream->buffer_left == -1) {
|
||||||
stream->buffer_left = 0;
|
stream->buffer_left = 0;
|
||||||
|
stream->buffer_fill = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,13 +520,13 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal buffer already contains requested amount
|
// Internal buffer already contains requested amount
|
||||||
memcpy(s, &stream->buffer[stream->buffer_size - stream->buffer_left], len);
|
memcpy(s, &stream->buffer[stream->buffer_fill - stream->buffer_left], len);
|
||||||
stream->buffer_left -= len;
|
stream->buffer_left -= len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Big read exceeding buffer size, exhaust small buffer and read rest in one go
|
// Big read exceeding buffer size, exhaust small buffer and read rest in one go
|
||||||
memcpy(s, &stream->buffer[stream->buffer_size - stream->buffer_left], stream->buffer_left);
|
memcpy(s, &stream->buffer[stream->buffer_fill - stream->buffer_left], stream->buffer_left);
|
||||||
len -= stream->buffer_left;
|
len -= stream->buffer_left;
|
||||||
bytes_read += stream->buffer_left;
|
bytes_read += stream->buffer_left;
|
||||||
stream->buffer_left = 0;
|
stream->buffer_left = 0;
|
||||||
|
@ -540,7 +543,6 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes_read + ret;
|
return bytes_read + ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue