Fix freeze when include file is a directory

Fixes #41.
This commit is contained in:
Zeex 2015-02-22 22:49:12 +06:00
parent 8bb8671f1e
commit cebb44800e

View File

@ -124,22 +124,19 @@ SC_FUNC void clearstk(void)
SC_FUNC int plungequalifiedfile(char *name)
{
static char *extensions[] = { ".inc", ".p", ".pawn" };
static char *extensions[] = { ".inc", ".p", ".pawn", "" };
FILE *fp;
char *ext;
int ext_idx;
ext_idx=0;
do {
fp=(FILE*)pc_opensrc(name);
ext=strchr(name,'\0'); /* save position */
if (fp==NULL) {
/* try to append an extension */
strcpy(ext,extensions[ext_idx]);
fp=(FILE*)pc_opensrc(name);
if (fp==NULL)
*ext='\0'; /* on failure, restore filename */
} /* if */
/* try to append an extension */
strcpy(ext,extensions[ext_idx]);
fp=pc_opensrc(name);
if (fp==NULL)
*ext='\0'; /* on failure, restore filename */
ext_idx++;
} while (fp==NULL && ext_idx<(sizeof extensions / sizeof extensions[0]));
if (fp==NULL) {
@ -3020,4 +3017,3 @@ static char itohstr[30];
*ptr='\0'; /* and a zero-terminator */
return itohstr;
}