static MVLentry *mvl_find_entry(const MVLinfo *info, const char *name) { char *ptr = strchr(name, '.'); MVLentry *a = info->entries; PHYSFS_sint32 lo = 0; PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1); PHYSFS_sint32 middle; int rc; /* * Rule out filenames to avoid unneeded processing...no dirs, * big filenames, or extensions > 3 chars. */ BAIL_IF_MACRO((ptr) && (strlen(ptr) > 4), ERR_NO_SUCH_FILE, NULL); BAIL_IF_MACRO(strlen(name) > 12, ERR_NO_SUCH_FILE, NULL); BAIL_IF_MACRO(strchr(name, '/') != NULL, ERR_NO_SUCH_FILE, NULL); while (lo <= hi) { middle = lo + ((hi - lo) / 2); rc = __PHYSFS_stricmpASCII(name, a[middle].name); if (rc == 0) /* found it! */ return &a[middle]; else if (rc > 0) lo = middle + 1; else hi = middle - 1; } /* while */ BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); } /* mvl_find_entry */
static int entryCmp(void *_a, size_t one, size_t two) { if (one != two) { const UNPKentry *a = (const UNPKentry *) _a; return __PHYSFS_stricmpASCII(a[one].name, a[two].name); } /* if */ return 0; } /* entryCmp */