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

Function default_search_paths

src/main.cpp:70–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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