MCPcopy Index your code
hub / github.com/NetHack/NetHack / compare_critical_bytes

Function compare_critical_bytes

src/version.c:762–823  ·  view source on GitHub ↗

* returns: * * SF_UPTODATE (0) everything matched and looks good * SF_OUTDATED (1) savefile is outdated * SF_CRITICAL_BYTE_COUNT_MISMATCH (2) critical size count mismatch * SF_DM_IL32LLP64_ON_ILP32LL64 (3) Windows x64 savefile on x86 * SF_DM_I32LP64_ON_ILP32LL64 (4) Unix 64 savefile on x86 * SF_DM_ILP32LL64_ON_I32LP64 (5) x86

Source from the content-addressed store, hash-verified

760 * SF_DM_MISMATCH (9) some other mismatch
761 */
762int
763compare_critical_bytes(NHFILE *nhfp, int *idx_1st_mismatch, unsigned long utdflags)
764{
765 char active_csc_count = (char) SIZE(critical_sizes),
766 file_csc_count;
767 int i, cnt = (int) active_csc_count,
768 dmmismatch = SF_DM_MISMATCH;
769 boolean quietly = (utdflags & UTD_QUIETLY) != 0;
770
771 Sfi_char(nhfp, &file_csc_count, "count-critical_sizes", 1);
772 if (file_csc_count > cnt) {
773 if (!quietly)
774 raw_printf("critical byte counts do not match"
775 ", file:%d, critical_sizes:%d.",
776 file_csc_count, SIZE(critical_sizes));
777 return SF_CRITICAL_BYTE_COUNT_MISMATCH;
778 }
779 for (i = 0; i < (int) file_csc_count; ++i) {
780 Sfi_uchar(nhfp, &cscbuf[i], "critical_sizes");
781 }
782 for (i = 1; i < cnt; ++i) {
783 if (cscbuf[i] != critical_sizes[i].ucsize) {
784 const char *dm = datamodel(0), *dmfile;
785
786 dmfile = what_datamodel_is_this(0,
787 cscbuf[1], /* short */
788 cscbuf[2], /* int */
789 cscbuf[3], /* long */
790 cscbuf[4], /* long long */
791 cscbuf[5]); /* ptr */
792
793 if (!strcmp(dmfile, "IL32LLP64") && !strcmp(dm, "ILP32LL64")) {
794 /* Windows x64 savefile on x86 */
795 dmmismatch = SF_DM_IL32LLP64_ON_ILP32LL64;
796 } else if (!strcmp(dmfile, "I32LP64")
797 && !strcmp(dm, "ILP32LL64")) {
798 /* Unix 64 savefile on x86*/
799 dmmismatch = SF_DM_I32LP64_ON_ILP32LL64;
800 } else if (!strcmp(dmfile, "ILP32LL64")
801 && !strcmp(dm, "I32LP64")) {
802 /* x86 savefile on Unix 64 */
803 dmmismatch = SF_DM_ILP32LL64_ON_I32LP64;
804 } else if (!strcmp(dmfile, "ILP32LL64")
805 && !strcmp(dm, "IL32LLP64")) {
806 /* x86 savefile on Windows x64 */
807 dmmismatch = SF_DM_ILP32LL64_ON_IL32LLP64;
808 } else if (!strcmp(dmfile, "I32LP64")
809 && !strcmp(dm, "IL32LLP64")) {
810 /* Unix 64 savefile on Windows x64 */
811 dmmismatch = SF_DM_I32LP64_ON_IL32LLP64;
812 } else if (!strcmp(dmfile, "IL32LLP64")
813 && !strcmp(dm, "I32LP64")) {
814 /* Windows x64 savefile on Unix 64 */
815 dmmismatch = SF_DM_IL32LLP64_ON_I32LP64;
816 }
817 if (idx_1st_mismatch)
818 *idx_1st_mismatch = i;
819 return dmmismatch;

Callers 1

uptodateFunction · 0.85

Calls 3

datamodelFunction · 0.85
what_datamodel_is_thisFunction · 0.85
raw_printfFunction · 0.70

Tested by

no test coverage detected