+/** Find the path of the binary file from the name found in argv */
+static std::string get_binary_path()
+{
+ struct stat stat_buf;
+
+ if (xbt_binary_name == nullptr)
+ return "";
+
+ // We found it, we are happy:
+ if (stat(xbt_binary_name, &stat_buf) == 0)
+ return xbt_binary_name;
+
+ // Not found, look in the PATH:
+ char* path = getenv("PATH");
+ if (path == nullptr)
+ return "";
+ XBT_DEBUG("Looking in the PATH: %s\n", path);
+ std::vector<std::string> path_list;
+ // TODO, on Windows, this is ";"
+ boost::split(path_list, path, boost::is_any_of(":"));
+ for (std::string const& path_item : path_list) {
+ std::string binary_name = simgrid::xbt::string_printf(
+ "%s/%s", path_item.c_str(), xbt_binary_name);
+ bool found = (stat(binary_name.c_str(), &stat_buf) == 0);
+ XBT_DEBUG("Looked in the PATH for the binary. %s %s",
+ found ? "Found" : "Not found",
+ binary_name.c_str());
+ if (found)
+ return binary_name;
+ }
+
+ // Not found at all:
+ return "";
+}
+