dep/libchdr: Add option to transfer file ownership

This commit is contained in:
Stenzek 2023-08-12 14:35:37 +10:00
parent 62c5e3af2f
commit bd1cf91030
2 changed files with 8 additions and 1 deletions

View file

@ -256,6 +256,7 @@ extern "C" {
/* CHD open values */
#define CHD_OPEN_READ 1
#define CHD_OPEN_READWRITE 2
#define CHD_OPEN_TRANSFER_FILE 4 /* Freeing of the FILE* is now libchdr's responsibility if open was successful */
/* error types */
enum _chd_error

View file

@ -1528,7 +1528,13 @@ CHD_EXPORT chd_error chd_open_file(FILE *file, int mode, chd_file *parent, chd_f
stream->fclose = core_stdio_fclose_nonowner;
stream->fseek = core_stdio_fseek;
return chd_open_core_file(stream, mode, parent, chd);
chd_error err = chd_open_core_file(stream, mode, parent, chd);
if (err != CHDERR_NONE)
return err;
// swap out the fclose so that we close it on chd clost
stream->fclose = core_stdio_fclose;
return CHDERR_NONE;
}
/*-------------------------------------------------