MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / isSubDirectory

Method isSubDirectory

engine/source/platformEmscripten/EmscriptenFileio.cpp:964–1005  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

962
963//-----------------------------------------------------------------------------
964bool Platform::isSubDirectory(const char *pParent, const char *pDir)
965{
966 if (!pParent || !*pDir)
967 return false;
968
969 // this is somewhat of a brute force method but we need to be 100% sure
970 // that the user cannot enter things like ../dir or /dir etc,...
971 DIR *directory;
972
973 directory = opendir(pParent);
974 if (directory == NULL)
975 return false;
976
977 struct dirent *fEntry;
978 fEntry = readdir(directory);
979 if ( fEntry == NULL )
980 return false;
981
982 do
983 {
984 char dirBuf[MAXPATHLEN];
985 struct stat fStat;
986
987 dSprintf(dirBuf, sizeof(dirBuf), "%s/%s", pParent, fEntry->d_name);
988 if (stat(dirBuf, &fStat) < 0)
989 continue;
990 // if it is a directory...
991 if ( (fStat.st_mode & S_IFMT) == S_IFDIR)
992 {
993 // and the names match
994 if (dStrcmp(pDir, fEntry->d_name ) == 0)
995 {
996 // then we have a real sub directory
997 closedir(directory);
998 return true;
999 }
1000 }
1001 } while( (fEntry = readdir(directory)) != NULL );
1002
1003 closedir(directory);
1004 return false;
1005}
1006
1007//-----------------------------------------------------------------------------
1008

Callers

nothing calls this directly

Calls 3

dSprintfFunction · 0.70
statClass · 0.70
dStrcmpFunction · 0.70

Tested by

no test coverage detected