EXAMPLES
Example 1: Using dlinfo to retrieve
.Vt Link_map structure. The following example shows how dynamic library can detect the list of shared libraries loaded after callers one. For simplicity, error checking has been omitted.
Link_map *map;
dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map);
while (map != NULL) {
printf("%p: %s\n", map->l_addr, map->l_name);
map = map->l_next;
}
Example 2: Using dlinfo to retrieve the library search paths.
The following example shows how a dynamic object can inspect the library search paths that would be used to locate a simple filename with dlopen(3). For simplicity, error checking has been omitted.
Dl_serinfo _info, *info = &_info;
Dl_serpath *path;
unsigned intcnt;
/* determine search path count and required buffer size */
dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info);
/* allocate new buffer and initialize */
info = malloc(_info.dls_size);
info->dls_size = _info.dls_size;
info->dls_cnt = _info.dls_cnt;
/* obtain sarch path information */
dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info);
path = &info->dls_serpath[0];
for (cnt = 1; cnt <= info->dls_cnt; cnt++, path++) {
(void) printf("%2d: %s\n", cnt, path->dls_name);
}
SEE ALSO
rtld(1), dladdr(3), dlopen(3), dlsym(3)
HISTORY
AUTHORS