aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneonloop2023-02-05 23:57:20 +0000
committerneonloop2023-02-05 23:57:20 +0000
commit670adf41511b9c04ef73e8acf40867c5b11c01f2 (patch)
treee1ac0e973d78b7f9b5b7f55d207164493e95b04d
parent409b69e43168561358bfb8b5759ec201a68ecc86 (diff)
downloadpicoarch-670adf41511b9c04ef73e8acf40867c5b11c01f2.tar.gz
picoarch-670adf41511b9c04ef73e8acf40867c5b11c01f2.tar.bz2
picoarch-670adf41511b9c04ef73e8acf40867c5b11c01f2.zip
Uses file size instead of core-reported size for state loads
Fixes dosbox-pure and other cores with varying state sizes
-rw-r--r--core.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/core.c b/core.c
index b758e7c..61a14b5 100644
--- a/core.c
+++ b/core.c
@@ -133,26 +133,30 @@ bool state_exists(int slot) {
int state_read(void) {
char filename[MAX_PATH];
+ struct stat stat;
+ size_t state_size;
FILE *state_file = NULL;
void *state = NULL;
int ret = -1;
- size_t state_size = current_core.retro_serialize_size();
- if (!state_size) {
- return 0;
+ state_file_name(filename, MAX_PATH, state_slot);
+
+ state_file = fopen(filename, "r");
+ if (!state_file) {
+ PA_ERROR("Error opening state file: %s\n", strerror(errno));
+ goto error;
}
- state = calloc(1, state_size);
- if (!state) {
- PA_ERROR("Couldn't allocate memory for state\n");
+ if (fstat(fileno(state_file), &stat) == -1) {
+ PA_ERROR("Couldn't read state file size: %s\n", strerror(errno));
goto error;
}
- state_file_name(filename, MAX_PATH, state_slot);
+ state_size = stat.st_size;
- state_file = fopen(filename, "r");
- if (!state_file) {
- PA_ERROR("Error opening state file: %s\n", strerror(errno));
+ state = calloc(1, state_size);
+ if (!state) {
+ PA_ERROR("Couldn't allocate memory for state\n");
goto error;
}