MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / util_PathFind

Function util_PathFind

src/core/unixfsservices.cpp:941–1012  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// Function name : util_PathFind Description : takes single-element executible filename and looks in path env var for it assumes path is colon-delimited string of directories. Return type : bool Argument : TSTRING& strFullPath Argument : const TSTRING& strFilename ////////////////////////////////

Source from the content-addressed store, hash-verified

939// Argument : const TSTRING& strFilename
940///////////////////////////////////////////////////////////////////////////////
941bool util_PathFind(TSTRING& strFullPath, const TSTRING& strFilename)
942{
943 bool fFoundFile = false;
944
945 if (strFilename.empty())
946 return false;
947
948 //
949 // get the path environment variable
950 //
951 TCHAR* pszPathVar = getenv("PATH");
952 if (pszPathVar != NULL)
953 {
954 //
955 // cycle over characters in path looking for the ':'
956 //
957 TSTRING strCurPath;
958 TCHAR* pchTemp = pszPathVar;
959 bool fMorePaths = true;
960 do // while still more paths and haven't found file
961 {
962 //
963 // are we at the ':'?
964 //
965 if (*pchTemp && *pchTemp != _T(':')) // if we're not at the end of the path
966 {
967 strCurPath += *pchTemp;
968 }
969 else // we have found the ':'
970 {
971 //
972 // expand current path into a fully qualified path
973 // if it's empty, use current directory
974 //
975 TSTRING strFP;
976 if (strCurPath.empty())
977 strCurPath = _T(".");
978 if (iFSServices::GetInstance()->FullPath(strFP, strCurPath))
979 strCurPath = strFP;
980
981 //
982 // put the file together with the path dir
983 //
984 TSTRING strFullName = strCurPath;
985 util_TrailingSep(strFullName, true);
986 strFullName += strFilename;
987
988 //
989 // the file must exist and be executable
990 //
991 if (util_FileIsExecutable(strFullName))
992 {
993 strFullPath = strFullName;
994 fFoundFile = true;
995 }
996 else
997 strCurPath.erase(); // start over
998 }

Callers 1

GetExecutableFilenameMethod · 0.85

Calls 4

util_TrailingSepFunction · 0.85
util_FileIsExecutableFunction · 0.85
emptyMethod · 0.80
FullPathMethod · 0.80

Tested by

no test coverage detected