Get rid of stack overflow code because filesystem case insensitivity is Windows exlcusive, so we can just create a wrapper function for there instead of rolling our own.

This commit is contained in:
toasterbabe 2017-04-29 16:40:07 +01:00
parent b2cbbb63c6
commit afe24bd4f0
3 changed files with 23 additions and 44 deletions

View File

@ -170,10 +170,6 @@ size_t strlcat(char *dst, const char *src, size_t siz);
size_t strlcpy(char *dst, const char *src, size_t siz);
#endif
#if 1 // don't know what systems don't have this
char* stristr(char* haystack, const char* needle);
#endif
// Macro for use with char foo[FOOSIZE+1] type buffers.
// Never use this with a buffer that is a "char *" or passed
// into the function as an argument.

View File

@ -510,7 +510,19 @@ char exttable[NUM_EXT_TABLE][5] = {
char filenamebuf[MAX_WADFILES][MAX_WADPATH];
#define searchdir if (menusearch[0] && !stristr(dent->d_name, menusearch+1))\
#ifdef _WIN32
static char *strsystemstr(char *haystack, char *needle)
{
char uprhaystack[128];
strlcpy(uprhaystack, haystack, 128);
strupr(uprhaystack);
return strstr(uprhaystack, needle);
}
#else
#define strsystemstr(haystack, needle) strstr(haystack, needle)
#endif
#define searchdir if (menusearch[0] && !strsystemstr(dent->d_name, localmenusearch))\
{\
rejected++;\
continue;\
@ -524,6 +536,7 @@ boolean preparefilemenu(boolean samedepth)
size_t pos = 0, folderpos = 0, numfolders = 0, rejected = 0;
char *tempname = NULL;
boolean noresults = false;
char localmenusearch[MAXSTRINGLENGTH] = "";
if (samedepth)
{
@ -544,6 +557,14 @@ boolean preparefilemenu(boolean samedepth)
if (dirhandle == NULL)
return false;
if (menusearch[0])
{
strcpy(localmenusearch, menusearch+1);
#ifdef _WIN32
strupr(localmenusearch);
#endif
}
while (true)
{
menupath[menupathindex[menudepthleft]] = 0;
@ -651,7 +672,7 @@ boolean preparefilemenu(boolean samedepth)
filenamebuf[i][MAX_WADPATH - 1] = '\0';
nameonly(filenamebuf[i]);
}
if (strcasecmp(dent->d_name, filenamebuf[i]))
if (strcmp(dent->d_name, filenamebuf[i]))
continue;
if (checkfilemd5(menupath, wadfiles[i]->md5sum))
ext |= EXT_LOADED;

View File

@ -49,42 +49,4 @@ size_t strlcpy(char *dst, const char *src, size_t siz)
return strlcat(dst, src, siz);
}
#endif
#if 1 // i don't know what specific OSes are missing this, oh well
// stack overflow, eep...
char* stristr(char* haystack, const char* needle)
{
char* p1 = haystack;
const char* p2 = needle;
char* r = ((*p2 == 0) ? haystack : 0);
while (*p1 != 0 && *p2 != 0)
{
if (tolower(*p1) == tolower(*p2))
{
if (r == 0)
r = p1;
p2++;
}
else
{
p2 = needle;
if (tolower(*p1) == tolower(*p2))
{
r = p1;
p2++;
}
else
r = 0;
}
p1++;
}
return ((*p2 == 0) ? r : 0);
}
#endif