From bd1cf9103006e20cbfd368d7fa118ed8cf939456 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 12 Aug 2023 14:35:37 +1000 Subject: [PATCH] dep/libchdr: Add option to transfer file ownership --- dep/libchdr/include/libchdr/chd.h | 1 + dep/libchdr/src/libchdr_chd.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dep/libchdr/include/libchdr/chd.h b/dep/libchdr/include/libchdr/chd.h index 33104d7cce..403a4303b1 100644 --- a/dep/libchdr/include/libchdr/chd.h +++ b/dep/libchdr/include/libchdr/chd.h @@ -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 diff --git a/dep/libchdr/src/libchdr_chd.c b/dep/libchdr/src/libchdr_chd.c index 79661f97a4..61acd11f12 100644 --- a/dep/libchdr/src/libchdr_chd.c +++ b/dep/libchdr/src/libchdr_chd.c @@ -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; } /*-------------------------------------------------