MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / getLoadedLibraries

Function getLoadedLibraries

src/version.cpp:122–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122static std::vector<std::string> getLoadedLibraries() {
123 std::vector<std::string> libs;
124 std::set<std::string> paths;
125 std::string path;
126
127#if defined(_WIN32) || defined(__CYGWIN__)
128// enumerate loaded libraries and determine path to executable (unsupported on UWP)
129#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_APP)
130 HMODULE handles[200];
131 DWORD cbNeeded;
132 if (EnumProcessModules(GetCurrentProcess(), handles, static_cast<DWORD>(std::size(handles)), &cbNeeded)) {
133 char szFilename[_MAX_PATH];
134 for (DWORD h = 0; h < cbNeeded / sizeof(handles[0]); h++) {
135 GetModuleFileNameA(handles[h], szFilename, static_cast<DWORD>(std::size(szFilename)));
136 pushPath(szFilename, libs, paths);
137 }
138 }
139#endif
140#elif defined(__APPLE__)
141 // man 3 dyld
142 uint32_t count = _dyld_image_count();
143 for (uint32_t image = 0; image < count; image++) {
144 std::string path(_dyld_get_image_name(image));
145 pushPath(path, libs, paths);
146 }
147#elif defined(__FreeBSD__)
148 {
149 unsigned int n;
150 struct procstat* procstat = procstat_open_sysctl();
151 struct kinfo_proc* procs = procstat ? procstat_getprocs(procstat, KERN_PROC_PID, getpid(), &n) : nullptr;
152 struct filestat_list* files = procs ? procstat_getfiles(procstat, procs, true) : nullptr;
153 if (files) {
154 filestat* entry;
155 STAILQ_FOREACH(entry, files, next) {
156 if (entry && PS_FST_TYPE_VNODE == entry->fs_type && entry->fs_path) {
157 std::string path(entry->fs_path);
158 pushPath(path, libs, paths);
159 }
160 }
161 }
162 // free resources
163 if (files)
164 procstat_freefiles(procstat, files);
165 if (procs)
166 procstat_freeprocs(procstat, procs);
167 if (procstat)
168 procstat_close(procstat);
169 }
170#elif defined(__sun__) || defined(__unix__)
171 // http://stackoverflow.com/questions/606041/how-do-i-get-the-path-of-a-process-in-unix-linux
172 char procsz[100];
173 char pathsz[500];
174 snprintf(procsz, sizeof(procsz), "/proc/%d/path/a.out", getpid());
175 if (auto l = readlink(procsz, pathsz, sizeof(pathsz) - 1); l > 0) {
176 pathsz[l] = '\0';
177 path.assign(pathsz);
178 libs.push_back(path);
179 }

Callers 1

dumpLibraryInfoMethod · 0.85

Calls 3

sizeFunction · 0.85
pushPathFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected