]> git.ipfire.org Git - thirdparty/glibc.git/blame - dlfcn/tst-dladdr.c
time: Allow later version licensing.
[thirdparty/glibc.git] / dlfcn / tst-dladdr.c
CommitLineData
00213fe4 1/* Test for dladdr.
dff8da6b 2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
41bdb6e2 3 This file is part of the GNU C Library.
00213fe4
AJ
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
00213fe4
AJ
9
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
41bdb6e2 13 Lesser General Public License for more details.
00213fe4 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
00213fe4
AJ
18
19#include <dlfcn.h>
20#include <errno.h>
21#include <error.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26
27#define TEST_FUNCTION do_test ()
ed073f0e 28extern int do_test (void);
00213fe4
AJ
29
30int
31do_test (void)
32{
33 void *handle;
34 int (*sym) (void); /* We load ref1 from glreflib1.c. */
35 Dl_info info;
36 int ret;
37
38
39 handle = dlopen ("glreflib1.so", RTLD_NOW);
40 if (handle == NULL)
41 error (EXIT_FAILURE, 0, "cannot load: glreflib1.so");
42
43 sym = dlsym (handle, "ref1");
44 if (sym == NULL)
45 error (EXIT_FAILURE, 0, "dlsym failed");
46
47 memset (&info, 0, sizeof (info));
48 ret = dladdr (sym, &info);
49
50 if (ret == 0)
51 error (EXIT_FAILURE, 0, "dladdr failed");
52
00213fe4
AJ
53 printf ("ret = %d\n", ret);
54 printf ("info.dli_fname = %p (\"%s\")\n", info.dli_fname, info.dli_fname);
55 printf ("info.dli_fbase = %p\n", info.dli_fbase);
56 printf ("info.dli_sname = %p (\"%s\")\n", info.dli_sname, info.dli_sname);
57 printf ("info.dli_saddr = %p\n", info.dli_saddr);
58
59 if (info.dli_fname == NULL)
60 error (EXIT_FAILURE, 0, "dli_fname is NULL");
61 if (info.dli_fbase == NULL)
62 error (EXIT_FAILURE, 0, "dli_fbase is NULL");
63 if (info.dli_sname == NULL)
64 error (EXIT_FAILURE, 0, "dli_sname is NULL");
65 if (info.dli_saddr == NULL)
66 error (EXIT_FAILURE, 0, "dli_saddr is NULL");
67
68 dlclose (handle);
69
70 return 0;
71}
72
73
74#include "../test-skeleton.c"