#include "../include/Linker.hpp" #include "../include/FileUtil.hpp" static void split_string(const std::string &str, char delimiter, std::function callback) { size_t index = 0; while(index < str.size()) { size_t end_index = str.find(delimiter, index); if(end_index == std::string::npos) end_index = str.size(); if(!callback(&str[index], end_index - index)) break; index = end_index + 1; } } namespace sibs { static bool is_linker_installed(const char *linker_binary_name) { const char *path = getenv("PATH"); if(!path) return false; bool linker_found = false; split_string(path, ':', [&](const char *str, size_t size) { std::string fullpath(str, size); fullpath += "/"; fullpath += linker_binary_name; if(getFileType(fullpath.c_str()) == FileType::REGULAR) { linker_found = true; return false; } return true; }); return linker_found; } bool is_gold_linker_installed() { return is_linker_installed("ld.gold"); } bool is_lld_linker_installed() { return is_linker_installed("ld.lld"); } bool is_mold_linker_installed() { return is_linker_installed("ld.mold") && fileExists("/usr/lib/mold/ld"); } }