Here is a way to scan all the paths stored in the PATH variable to scan the mathsat :
#include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <string> #include <iostream> using namespace std; int main () { struct stat sb; string delimiter = ":"; string path = string(getenv("PATH")); size_t start_pos = 0, end_pos = 0; while ((end_pos = path.find(':', start_pos)) != string::npos) { string current_path = path.substr(start_pos, end_pos - start_pos) + "/mathsat"; if ((stat(mathsat_path.c_str(), &sb) == 0) && (sb.st_mode & S_IXOTH)) { cout << "Okay" << endl; return EXIT_SUCCESS; } start_pos = end_pos + 1; } return EXIT_SUCCESS; }
source share