add access to location where findfile() found the file

"findfilelocation" contains the location, where the file was found.
Not a nice solution, but nice enough :)

Note: if the location is FFL_WORKDIR, the existence of the file has not
actually been checked yet.
This commit is contained in:
ac-stef
2015-06-05 16:00:02 +02:00
parent 00fab48b94
commit fb3a04d5da
2 changed files with 7 additions and 0 deletions
+5
View File
@@ -217,12 +217,15 @@ void addpackagedir(const char *dir)
}
}
int findfilelocation;
const char *findfile(const char *filename, const char *mode)
{
while(filename[0] == PATHDIV) filename++; // skip leading pathdiv
while(!strncmp(".." PATHDIVS, filename, 3)) filename += 3; // skip leading "../" (don't allow access to files below "AC root dir")
static string s;
formatstring(s)("%s%s", homedir, filename); // homedir may be ""
findfilelocation = FFL_HOME;
if(homedir[0] && fileexists(s, mode)) return s;
if(mode[0]=='w' || mode[0]=='a')
{ // create missing directories, if necessary
@@ -240,9 +243,11 @@ const char *findfile(const char *filename, const char *mode)
}
loopv(packagedirs)
{
findfilelocation++;
formatstring(s)("%s%s", packagedirs[i], filename);
if(fileexists(s, mode)) return s;
}
findfilelocation = FFL_WORKDIR;
return filename;
}
+2
View File
@@ -953,6 +953,8 @@ extern bool createdir(const char *path);
extern size_t fixpackagedir(char *dir);
extern void sethomedir(const char *dir);
extern void addpackagedir(const char *dir);
extern int findfilelocation;
enum { FFL_WORKDIR = -1, FFL_HOME = 0 };
extern const char *findfile(const char *filename, const char *mode);
extern int getfilesize(const char *filename);
extern stream *openrawfile(const char *filename, const char *mode);