/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "save/save.h" #include "util/string.h" #include #include #include errorret_t saveInitLinux(void) { stringCopy(SAVE.platform.savePath, SAVE_LINUX_PATH, SAVE_LINUX_PATH_MAX); if(mkdir(SAVE.platform.savePath, 0755) != 0 && errno != EEXIST) { errorThrow("Failed to create save directory: %s", SAVE.platform.savePath); } errorOk(); } errorret_t saveDisposeLinux(void) { errorOk(); } errorret_t saveLoadLinux(const uint8_t slot, savefile_t *file) { char_t path[SAVE_LINUX_PATH_MAX]; snprintf(path, SAVE_LINUX_PATH_MAX, SAVE_LINUX_FILE_FORMAT, SAVE.platform.savePath, (uint32_t)slot ); FILE *f = fopen(path, "rb"); if(!f) { file->exists = false; errorOk(); } size_t read = fread(file, sizeof(savefile_t), 1, f); fclose(f); if(read != 1) { file->exists = false; errorThrow("Failed to read save data for slot %u", (uint32_t)slot); } file->exists = true; errorOk(); } errorret_t saveWriteLinux(const uint8_t slot, const savefile_t *file) { char_t path[SAVE_LINUX_PATH_MAX]; snprintf(path, SAVE_LINUX_PATH_MAX, SAVE_LINUX_FILE_FORMAT, SAVE.platform.savePath, (uint32_t)slot ); FILE *f = fopen(path, "wb"); if(!f) { errorThrow("Failed to open save file for writing: slot %u", (uint32_t)slot); } size_t written = fwrite(file, sizeof(savefile_t), 1, f); fclose(f); if(written != 1) { errorThrow("Failed to write save data for slot %u", (uint32_t)slot); } errorOk(); } errorret_t saveDeleteLinux(const uint8_t slot) { char_t path[SAVE_LINUX_PATH_MAX]; snprintf(path, SAVE_LINUX_PATH_MAX, SAVE_LINUX_FILE_FORMAT, SAVE.platform.savePath, (uint32_t)slot ); if(remove(path) != 0 && errno != ENOENT) { errorThrow("Failed to delete save file for slot %u", (uint32_t)slot); } errorOk(); }