////////////////////////////////////////////////////////////////////////// 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 ////////////////////////////////
| 939 | // Argument : const TSTRING& strFilename |
| 940 | /////////////////////////////////////////////////////////////////////////////// |
| 941 | bool 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 | } |
no test coverage detected