dep/libchdr: Add chd_is_matching_parent()

This commit is contained in:
Stenzek 2023-08-12 14:40:19 +10:00
parent bd1cf91030
commit f41384c6c8
2 changed files with 23 additions and 0 deletions

View file

@ -48,6 +48,7 @@ extern "C" {
#include <libchdr/coretypes.h> #include <libchdr/coretypes.h>
#include <libchdr/chdconfig.h> #include <libchdr/chdconfig.h>
#include <stdbool.h>
/*************************************************************************** /***************************************************************************
@ -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_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_file(FILE *file, chd_header *header);
CHD_EXPORT chd_error chd_read_header(const char *filename, 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);

View file

@ -2056,6 +2056,27 @@ CHD_EXPORT chd_error chd_read_header(const char *filename, chd_header *header)
return err; 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 CORE DATA READ/WRITE
***************************************************************************/ ***************************************************************************/