diff --git a/Core/apu.c b/Core/apu.c index 7454e26fc..84bed5da5 100644 --- a/Core/apu.c +++ b/Core/apu.c @@ -1854,18 +1854,20 @@ int GB_start_audio_recording(GB_gameboy_t *gb, const char *path, GB_audio_format case GB_AUDIO_FORMAT_AIFF: { aiff_header_t header = {0,}; if (fwrite(&header, sizeof(header), 1, gb->apu_output.output_file) != 1) { + int ret = errno ?: EIO; fclose(gb->apu_output.output_file); gb->apu_output.output_file = NULL; - return errno; + return ret; } return 0; } case GB_AUDIO_FORMAT_WAV: { wav_header_t header = {0,}; if (fwrite(&header, sizeof(header), 1, gb->apu_output.output_file) != 1) { + int ret = errno ?: EIO; fclose(gb->apu_output.output_file); gb->apu_output.output_file = NULL; - return errno; + return ret; } return 0; } diff --git a/Core/cheats.c b/Core/cheats.c index b3bc2e7b6..cf2a69054 100644 --- a/Core/cheats.c +++ b/Core/cheats.c @@ -338,7 +338,6 @@ int GB_save_cheats(GB_gameboy_t *gb, const char *path) } } - errno = 0; fclose(f); - return errno; + return 0; } diff --git a/Core/gb.c b/Core/gb.c index fafe6cd17..c4398d3b2 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -15,6 +15,7 @@ void GB_attributed_logv(GB_gameboy_t *gb, GB_log_attributes_t attributes, const char *fmt, va_list args) { + int errno_backup = errno; char *string = NULL; vasprintf(&string, fmt, args); if (string) { @@ -27,6 +28,7 @@ void GB_attributed_logv(GB_gameboy_t *gb, GB_log_attributes_t attributes, const } } free(string); + errno = errno_backup; } void GB_attributed_log(GB_gameboy_t *gb, GB_log_attributes_t attributes, const char *fmt, ...) @@ -877,8 +879,7 @@ int GB_save_battery_to_buffer(GB_gameboy_t *gb, uint8_t *buffer, size_t size) memcpy(buffer + gb->mbc_ram_size, &rtc_save.vba64, sizeof(rtc_save.vba64)); } - errno = 0; - return errno; + return 0; } int GB_save_battery(GB_gameboy_t *gb, const char *path) @@ -942,9 +943,8 @@ int GB_save_battery(GB_gameboy_t *gb, const char *path) } - errno = 0; fclose(f); - return errno; + return 0; } static void load_tpp1_save_data(GB_gameboy_t *gb, const tpp1_rtc_save_t *data) diff --git a/Core/save_state.c b/Core/save_state.c index be725a474..8a9a467e1 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -834,9 +834,8 @@ static int save_state_internal(GB_gameboy_t *gb, virtual_file_t *file, bool appe goto error; } - errno = 0; error: - return errno; + return 0; } int GB_save_state(GB_gameboy_t *gb, const char *path)