| 69 | } |
| 70 | |
| 71 | std::vector<std::string> default_search_paths() |
| 72 | { |
| 73 | std::vector<std::string> paths; |
| 74 | |
| 75 | #ifndef CHAISCRIPT_NO_DYNLOAD |
| 76 | #ifdef CHAISCRIPT_WINDOWS // force no unicode |
| 77 | CHAR path[4096]; |
| 78 | int size = GetModuleFileNameA(nullptr, path, sizeof(path)-1); |
| 79 | |
| 80 | std::string exepath(path, size); |
| 81 | |
| 82 | size_t lastslash = exepath.rfind('\\'); |
| 83 | size_t secondtolastslash = exepath.rfind('\\', lastslash - 1); |
| 84 | if (lastslash != std::string::npos) |
| 85 | { |
| 86 | paths.push_back(exepath.substr(0, lastslash)); |
| 87 | } |
| 88 | |
| 89 | if (secondtolastslash != std::string::npos) |
| 90 | { |
| 91 | return {exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\"}; |
| 92 | } |
| 93 | #else |
| 94 | |
| 95 | std::string exepath; |
| 96 | |
| 97 | std::vector<char> buf(2048); |
| 98 | ssize_t size = -1; |
| 99 | |
| 100 | if ((size = readlink("/proc/self/exe", &buf.front(), buf.size())) >= 0) |
| 101 | { |
| 102 | exepath = std::string(&buf.front(), static_cast<size_t>(size)); |
| 103 | } |
| 104 | |
| 105 | if (exepath.empty()) |
| 106 | { |
| 107 | if ((size = readlink("/proc/curproc/file", &buf.front(), buf.size())) >= 0) |
| 108 | { |
| 109 | exepath = std::string(&buf.front(), static_cast<size_t>(size)); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (exepath.empty()) |
| 114 | { |
| 115 | if ((size = readlink("/proc/self/path/a.out", &buf.front(), buf.size())) >= 0) |
| 116 | { |
| 117 | exepath = std::string(&buf.front(), static_cast<size_t>(size)); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if (exepath.empty()) |
| 122 | { |
| 123 | Dl_info rInfo; |
| 124 | memset( &rInfo, 0, sizeof(rInfo) ); |
| 125 | if ( dladdr(cast_module_symbol(&default_search_paths), &rInfo) == 0 || rInfo.dli_fname == nullptr ) { |
| 126 | return paths; |
| 127 | } |
| 128 | |