MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / default_search_paths

Function default_search_paths

samples/fun_call_performance.cpp:67–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 6

stringClass · 0.85
substrMethod · 0.80
frontMethod · 0.80
cast_module_symbolFunction · 0.70
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected