From f41384c6c8180e086de2b428a98cd54aedd31937 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 12 Aug 2023 14:40:19 +1000 Subject: [PATCH] dep/libchdr: Add chd_is_matching_parent() --- dep/libchdr/include/libchdr/chd.h | 2 ++ dep/libchdr/src/libchdr_chd.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/dep/libchdr/include/libchdr/chd.h b/dep/libchdr/include/libchdr/chd.h index 403a4303b..0beed4903 100644 --- a/dep/libchdr/include/libchdr/chd.h +++ b/dep/libchdr/include/libchdr/chd.h @@ -48,6 +48,7 @@ extern "C" { #include #include +#include /*************************************************************************** @@ -402,6 +403,7 @@ CHD_EXPORT const chd_header *chd_get_header(chd_file *chd); CHD_EXPORT chd_error chd_read_header_core_file(core_file *file, chd_header *header); CHD_EXPORT chd_error chd_read_header_file(FILE *file, chd_header *header); CHD_EXPORT chd_error chd_read_header(const char *filename, chd_header *header); +CHD_EXPORT bool chd_is_matching_parent(const chd_header* header, const chd_header* parent_header); diff --git a/dep/libchdr/src/libchdr_chd.c b/dep/libchdr/src/libchdr_chd.c index 61acd11f1..8c65d7459 100644 --- a/dep/libchdr/src/libchdr_chd.c +++ b/dep/libchdr/src/libchdr_chd.c @@ -2056,6 +2056,27 @@ CHD_EXPORT chd_error chd_read_header(const char *filename, chd_header *header) return err; } +CHD_EXPORT bool chd_is_matching_parent(const chd_header* header, const chd_header* parent_header) +{ + /* check MD5 if it isn't empty */ + if (memcmp(nullmd5, header->parentmd5, sizeof(header->parentmd5)) != 0 && + memcmp(nullmd5, parent_header->md5, sizeof(parent_header->md5)) != 0 && + memcmp(parent_header->md5, header->parentmd5, sizeof(header->parentmd5)) != 0) + { + return false; + } + + /* check SHA1 if it isn't empty */ + if (memcmp(nullsha1, header->parentsha1, sizeof(header->parentsha1)) != 0 && + memcmp(nullsha1, parent_header->sha1, sizeof(parent_header->sha1)) != 0 && + memcmp(parent_header->sha1, header->parentsha1, sizeof(header->parentsha1)) != 0) + { + return false; + } + + return true; +} + /*************************************************************************** CORE DATA READ/WRITE ***************************************************************************/