Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / pdemo / longer_file_name_dlmain.c
1 /* dlmain.c -- hello test program that uses simulated dynamic linking
2
3    Copyright (C) 1996-1999, 2004, 2006, 2007, 2010 Free Software
4    Foundation, Inc.
5
6    This file is part of GNU Libtool.
7
8 GNU Libtool is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
12
13 GNU Libtool is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Libtool; see the file COPYING.  If not, a copy
20 can be downloaded from  http://www.gnu.org/licenses/gpl.html,
21 or obtained by writing to the Free Software Foundation, Inc.,
22 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24
25 #include "foo.h"
26 #include <stdio.h>
27 #include <string.h>
28
29 #define lt_preloaded_symbols lt__PROGRAM__LTX_preloaded_symbols
30
31 typedef struct
32 {
33   const char *name;
34   lt_ptr_t address;
35 } lt_dlsymlist;
36
37 extern LT_DLSYM_CONST lt_dlsymlist lt_preloaded_symbols[];
38
39 int
40 main (int argc, char **argv)
41 {
42   const lt_dlsymlist *s;
43   int (*pfoo)() = 0;
44   int (*phello)() = 0;
45   int *pnothing = 0;
46
47   printf ("Welcome to *modular* GNU Hell!\n");
48
49   /* Look up the symbols we require for this demonstration. */
50   s = lt_preloaded_symbols;
51   while (s->name)
52     {
53       if (s->address) {
54         const char *name = s->name;
55         printf ("found symbol: %s\n", name);
56         if (!strcmp ("hello", name))
57           phello = (int(*)())s->address;
58         else if (!strcmp ("foo", name))
59           pfoo = (int(*)())s->address;
60         else if (!strcmp ("nothing", name))
61 #ifndef _WIN32
62           /* In an ideal world we could do this... */
63           pnothing = (int*)s->address;
64 #else /* !_WIN32 */
65           /* In an ideal world a shared lib would be able to export data */
66           pnothing = (int*)&nothing;
67 #endif
68       } else
69         printf ("found file: %s\n", s->name);
70       s ++;
71     }
72
73   /* Try assigning to the nothing variable. */
74   if (pnothing)
75     *pnothing = 1;
76   else
77     fprintf (stderr, "did not find the `nothing' variable\n");
78
79   /* Just call the functions and check return values. */
80   if (pfoo)
81     {
82       if ((*pfoo) () != FOO_RET)
83         return 1;
84     }
85   else
86     fprintf (stderr, "did not find the `foo' function\n");
87
88   if (phello)
89     {
90       if ((*phello) () != HELLO_RET)
91         return 3;
92     }
93   else
94     fprintf (stderr, "did not find the `hello' function\n");
95
96   return 0;
97 }