1 |
|
/* dlmain.c -- hello test program that uses simulated dynamic linking |
2 |
|
Copyright (C) 1996-1999 Free Software Foundation, Inc. |
3 |
|
This file is part of GNU Libtool. |
4 |
|
|
5 |
|
This program is free software; you can redistribute it and/or modify |
6 |
|
it under the terms of the GNU General Public License as published by |
7 |
|
the Free Software Foundation; either version 2 of the License, or |
8 |
|
(at your option) any later version. |
9 |
|
|
10 |
|
This program 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 |
13 |
|
GNU General Public License for more details. |
14 |
|
|
15 |
|
You should have received a copy of the GNU General Public License |
16 |
|
along with this program; if not, write to the Free Software |
17 |
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
|
USA. */ |
19 |
|
|
20 |
|
#include "foo.h" |
21 |
|
#include <stdio.h> |
22 |
|
|
23 |
|
#ifdef HAVE_STRING_H |
24 |
|
#include <string.h> |
25 |
|
#endif |
26 |
|
|
27 |
|
struct lt_symlist |
28 |
|
{ |
29 |
|
const char *name; |
30 |
|
lt_ptr_t address; |
31 |
|
}; |
32 |
|
|
33 |
|
extern const struct lt_symlist lt_preloaded_symbols[]; |
34 |
|
|
35 |
|
int |
36 |
|
main (argc, argv) |
37 |
|
int argc; |
38 |
|
char **argv; |
39 |
|
{ |
40 |
|
const struct lt_symlist *s; |
41 |
|
int (*pfoo)() = 0; |
42 |
|
int (*phello)() = 0; |
43 |
|
int *pnothing = 0; |
44 |
|
|
45 |
|
printf ("Welcome to *modular* GNU Hell!\n"); |
46 |
|
|
47 |
|
/* Look up the symbols we require for this demonstration. */ |
48 |
|
s = lt_preloaded_symbols; |
49 |
|
while (s->name) |
50 |
|
{ |
51 |
|
if (s->address) { |
52 |
|
const char *name = s->name; |
53 |
|
printf ("found symbol: %s\n", name); |
54 |
|
if (!strcmp ("hello", name)) |
55 |
|
phello = (int(*)())s->address; |
56 |
|
else if (!strcmp ("foo", name)) |
57 |
|
pfoo = (int(*)())s->address; |
58 |
|
else if (!strcmp ("nothing", name)) |
59 |
|
#ifndef _WIN32 |
60 |
|
/* In an ideal world we could do this... */ |
61 |
|
pnothing = (int*)s->address; |
62 |
|
#else /* !_WIN32 */ |
63 |
|
/* In an ideal world a shared lib would be able to export data */ |
64 |
|
pnothing = (int*)¬hing; |
65 |
|
#endif |
66 |
|
} else |
67 |
|
printf ("found file: %s\n", s->name); |
68 |
|
s ++; |
69 |
|
} |
70 |
|
|
71 |
|
/* Try assigning to the nothing variable. */ |
72 |
|
if (pnothing) |
73 |
|
*pnothing = 1; |
74 |
|
else |
75 |
|
fprintf (stderr, "did not find the `nothing' variable\n"); |
76 |
|
|
77 |
|
/* Just call the functions and check return values. */ |
78 |
|
if (pfoo) |
79 |
|
{ |
80 |
|
if ((*pfoo) () != FOO_RET) |
81 |
|
return 1; |
82 |
|
} |
83 |
|
else |
84 |
|
fprintf (stderr, "did not find the `foo' function\n"); |
85 |
|
|
86 |
|
if (phello) |
87 |
|
{ |
88 |
|
if ((*phello) () != HELLO_RET) |
89 |
|
return 3; |
90 |
|
} |
91 |
|
else |
92 |
|
fprintf (stderr, "did not find the `hello' function\n"); |
93 |
|
|
94 |
|
return 0; |
95 |
|
} |