Update.
[glibc.git] / dlfcn / tst-dladdr.c
blobfb666ef8899b12750bc5c12ccfe2181b5cad5b4f
1 /* Test for dladdr.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 Contributed by Volkmar Sieh <vs@caldera.de> and Andreas Jaeger <aj@suse.de>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <dlfcn.h>
21 #include <errno.h>
22 #include <error.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
28 #define TEST_FUNCTION do_test ()
29 extern int do_test (void);
31 int
32 do_test (void)
34 void *handle;
35 int (*sym) (void); /* We load ref1 from glreflib1.c. */
36 Dl_info info;
37 int ret;
40 handle = dlopen ("glreflib1.so", RTLD_NOW);
41 if (handle == NULL)
42 error (EXIT_FAILURE, 0, "cannot load: glreflib1.so");
44 sym = dlsym (handle, "ref1");
45 if (sym == NULL)
46 error (EXIT_FAILURE, 0, "dlsym failed");
48 memset (&info, 0, sizeof (info));
49 ret = dladdr (sym, &info);
51 if (ret == 0)
52 error (EXIT_FAILURE, 0, "dladdr failed");
54 printf ("address of ref1 = %p\n", sym);
55 printf ("ret = %d\n", ret);
56 printf ("info.dli_fname = %p (\"%s\")\n", info.dli_fname, info.dli_fname);
57 printf ("info.dli_fbase = %p\n", info.dli_fbase);
58 printf ("info.dli_sname = %p (\"%s\")\n", info.dli_sname, info.dli_sname);
59 printf ("info.dli_saddr = %p\n", info.dli_saddr);
61 if (info.dli_fname == NULL)
62 error (EXIT_FAILURE, 0, "dli_fname is NULL");
63 if (info.dli_fbase == NULL)
64 error (EXIT_FAILURE, 0, "dli_fbase is NULL");
65 if (info.dli_sname == NULL)
66 error (EXIT_FAILURE, 0, "dli_sname is NULL");
67 if (info.dli_saddr == NULL)
68 error (EXIT_FAILURE, 0, "dli_saddr is NULL");
70 dlclose (handle);
72 return 0;
76 #include "../test-skeleton.c"