! * @brief Get the Tengine root path * @return The string of Tengine root path(e.g. "/home/user/tengine/") * @note Firstly, assume the program is under "Tengine_root/build/examples/..."; if failed, then assume the program is under "Tengine_root/examples/..."; * if failed, then assume the program is under Tengine_root; * if failed again, then return an empty string. */
| 12 | * if failed again, then return an empty string. |
| 13 | */ |
| 14 | std::string get_root_path(void) |
| 15 | { |
| 16 | typedef std::string::size_type pos; |
| 17 | char buf[1024]; |
| 18 | |
| 19 | int rslt = readlink("/proc/self/exe", buf, 1023); |
| 20 | if(rslt < 0 || rslt > 1023) |
| 21 | { |
| 22 | return std::string(""); |
| 23 | } |
| 24 | buf[rslt] = '\0'; |
| 25 | |
| 26 | std::string str = buf; |
| 27 | std::cout << str << std::endl; |
| 28 | pos p = str.find("build/examples/"); |
| 29 | if(p == std::string::npos) |
| 30 | { |
| 31 | p = str.find("examples/"); |
| 32 | if(p == std::string::npos) |
| 33 | { |
| 34 | p = str.find("tengine/"); |
| 35 | if(p == std::string::npos) |
| 36 | return std::string(""); |
| 37 | else |
| 38 | return str.substr(0, p + 8); |
| 39 | } |
| 40 | } |
| 41 | return str.substr(0, p); |
| 42 | } |
| 43 | |
| 44 | /*! |
| 45 | * @brief Find the config file and set it to tengine |
no outgoing calls