Skip to content

Commit

Permalink
dep/libchdr: Add option to transfer file ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 12, 2023
1 parent 62c5e3a commit bd1cf91
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions dep/libchdr/include/libchdr/chd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion dep/libchdr/src/libchdr_chd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*-------------------------------------------------
Expand Down

0 comments on commit bd1cf91

Please # to comment.