Add SOL_MPTCP, SOL_MCTP from Linux 5.16 to bits/socket.h
[glibc.git] / dlfcn / tst-dladdr.c
blobd8619b0afc236b31276bab15bc5314f82db772d9
1 /* Test for dladdr.
2 Copyright (C) 2000-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <dlfcn.h>
20 #include <errno.h>
21 #include <error.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
27 #define TEST_FUNCTION do_test ()
28 extern int do_test (void);
30 int
31 do_test (void)
33 void *handle;
34 int (*sym) (void); /* We load ref1 from glreflib1.c. */
35 Dl_info info;
36 int ret;
39 handle = dlopen ("glreflib1.so", RTLD_NOW);
40 if (handle == NULL)
41 error (EXIT_FAILURE, 0, "cannot load: glreflib1.so");
43 sym = dlsym (handle, "ref1");
44 if (sym == NULL)
45 error (EXIT_FAILURE, 0, "dlsym failed");
47 memset (&info, 0, sizeof (info));
48 ret = dladdr (sym, &info);
50 if (ret == 0)
51 error (EXIT_FAILURE, 0, "dladdr failed");
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);
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");
68 dlclose (handle);
70 return 0;
74 #include "../test-skeleton.c"