git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit c5362023c8d495cca0280bf87e51e7a034c693ba
parent bcfe36897cb6900b2f67cd0256e30fa3f300e8c5
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Mon, 25 Jul 2022 00:26:42 +0300

Fix false positives when detecting unwritable save paths

Diffstat:
MCocoa/Document.m12+++++++++++-
MSDL/main.c12+++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/Cocoa/Document.m b/Cocoa/Document.m @@ -1049,6 +1049,16 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) return fileName; } +static bool is_path_writeable(const char *path) +{ + if (!access(path, W_OK)) return true; + int fd = creat(path, 0644); + if (fd == -1) return false; + close(fd); + unlink(path); + return true; +} + - (int) loadROM { __block int ret = 0; @@ -1078,7 +1088,7 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) ret = GB_load_rom(&gb, [fileName UTF8String]); } if (GB_save_battery_size(&gb)) { - if (access(self.savPath.UTF8String, W_OK)) { + if (!is_path_writeable(self.savPath.UTF8String)) { GB_log(&gb, "The save path for this ROM is not writeable, progress will not be saved.\n"); } } diff --git a/SDL/main.c b/SDL/main.c @@ -656,6 +656,16 @@ static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type) } } +static bool is_path_writeable(const char *path) +{ + if (!access(path, W_OK)) return true; + int fd = creat(path, 0644); + if (fd == -1) return false; + close(fd); + unlink(path); + return true; +} + static void run(void) { SDL_ShowCursor(SDL_DISABLE); @@ -744,7 +754,7 @@ restart: battery_save_path_ptr = battery_save_path; GB_load_battery(&gb, battery_save_path); if (GB_save_battery_size(&gb)) { - if (access(battery_save_path, W_OK)) { + if (!is_path_writeable(battery_save_path)) { GB_log(&gb, "The save path for this ROM is not writeable, progress will not be saved.\n"); } }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.