Skip to content

Commit

Permalink
dep/libchdr: Add chd_is_matching_parent()
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 12, 2023
1 parent bd1cf91 commit f41384c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dep/libchdr/include/libchdr/chd.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern "C" {

#include <libchdr/coretypes.h>
#include <libchdr/chdconfig.h>
#include <stdbool.h>

/***************************************************************************
Expand Down Expand Up @@ -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);



Expand Down
21 changes: 21 additions & 0 deletions dep/libchdr/src/libchdr_chd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
***************************************************************************/
Expand Down

0 comments on commit f41384c

Please # to comment.