Add '/' as a portable path separator for #include

This fixes a bug where if you use '/' in an #include directive on Windows
the _inc_XXX symbol will contain not only the file name but also its path
as the compiler didn't count '/' as a path separator.
This commit is contained in:
Zeex 2014-01-06 22:23:18 +07:00
parent bf847442e9
commit b9050b452a
2 changed files with 7 additions and 1 deletions

View File

@ -66,6 +66,9 @@
#define DIRSEP_CHAR '/' /* directory separator character */
#endif
/* system-independent directory separator */
#define DIRSEP_CHAR_SI '/'
/* _MAX_PATH is sometimes called differently and it may be in limits.h or
* stdlib.h instead of stdio.h.
*/

View File

@ -183,7 +183,8 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
* there is a (relative) path for the current file
*/
char *ptr;
if ((ptr=strrchr(inpfname,DIRSEP_CHAR))!=0) {
if ((ptr=strrchr(inpfname,DIRSEP_CHAR))!=0 |
(ptr=strrchr(inpfname,DIRSEP_CHAR_SI))!=0) {
int len=(int)(ptr-inpfname)+1;
if (len+strlen(name)<_MAX_PATH) {
char path[_MAX_PATH];
@ -268,6 +269,8 @@ static void doinclude(int silent)
strcpy(symname,"_inc_");
if ((ptr=strrchr(name,DIRSEP_CHAR))!=NULL)
strlcat(symname,ptr+1,sizeof symname);
else if ((ptr=strrchr(name,DIRSEP_CHAR_SI))!=NULL)
strlcat(symname,ptr+1,sizeof symname);
else
strlcat(symname,name,sizeof symname);
if (find_symbol(&glbtab,symname,fcurrent,-1,NULL)==NULL) {