summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/dlinfo.3
diff options
context:
space:
mode:
authorphantom <phantom@FreeBSD.org>2003-02-15 10:51:05 +0000
committerphantom <phantom@FreeBSD.org>2003-02-15 10:51:05 +0000
commit861ecc30a5f80f5cc362120223114a665c17f21b (patch)
treeb95d9d81ace320bf511d755e0d24c217088d7930 /lib/libc/gen/dlinfo.3
parentcb6083f9802291b208d0d70b2a356afb604bf3cf (diff)
downloadFreeBSD-src-861ecc30a5f80f5cc362120223114a665c17f21b.zip
FreeBSD-src-861ecc30a5f80f5cc362120223114a665c17f21b.tar.gz
Add examples of dlinfo() usage to manual page.
Diffstat (limited to 'lib/libc/gen/dlinfo.3')
-rw-r--r--lib/libc/gen/dlinfo.349
1 files changed, 48 insertions, 1 deletions
diff --git a/lib/libc/gen/dlinfo.3 b/lib/libc/gen/dlinfo.3
index 48b5373..53ac258 100644
--- a/lib/libc/gen/dlinfo.3
+++ b/lib/libc/gen/dlinfo.3
@@ -182,7 +182,54 @@ pointer
.Ft ( char *p ) .
.El
.Sh EXAMPLES
-To be continued
+Example 1: Using
+.Fn dlinfo
+to retrieve Link_map structure.
+.Pp
+The following example shows how dynamic library can detect the list
+of shared libraries loaded after caller's one.
+For simplicity, error checking has been omitted.
+.Bd -literal
+ 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;
+ }
+.Ed
+.Pp
+Example 2: Using
+.Fn dlinfo
+to retrieve the library search paths.
+.Pp
+The following example shows how a dynamic object can inspect the library
+search paths that would be used to locate a simple filename with
+.Fn dlopen .
+For simplicity, error checking has been omitted.
+.Bd -literal
+ Dl_serinfo _info, *info = &_info;
+ Dl_serpath *path;
+ unsigned int cnt;
+
+ /* 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);
+ }
+.Ed
.Sh RETURN VALUES
.Fn dlinfo
returns 0 on success, or -1 if error occured.
OpenPOWER on IntegriCloud