icculus@2067
|
1 |
|
icculus@2067
|
2 |
/* Test program to test dynamic loading with the loadso subsystem.
|
icculus@2067
|
3 |
*/
|
icculus@2067
|
4 |
|
icculus@2067
|
5 |
#include <stdio.h>
|
icculus@2067
|
6 |
#include <stdlib.h>
|
icculus@2067
|
7 |
|
icculus@2067
|
8 |
#include "SDL.h"
|
icculus@2067
|
9 |
|
icculus@2067
|
10 |
typedef int (*fntype)(const char *);
|
icculus@2067
|
11 |
|
icculus@2067
|
12 |
int main(int argc, char *argv[])
|
icculus@2067
|
13 |
{
|
icculus@2067
|
14 |
int retval = 0;
|
icculus@2067
|
15 |
int hello = 0;
|
icculus@2067
|
16 |
const char *libname = NULL;
|
icculus@2067
|
17 |
const char *symname = NULL;
|
icculus@2067
|
18 |
void *lib = NULL;
|
icculus@2067
|
19 |
fntype fn = NULL;
|
icculus@2067
|
20 |
|
icculus@2067
|
21 |
if (argc != 3) {
|
icculus@2067
|
22 |
fprintf(stderr, "USAGE: %s <library> <functionname>\n");
|
icculus@2067
|
23 |
fprintf(stderr, " %s --hello <library with puts()>\n");
|
icculus@2067
|
24 |
return 1;
|
icculus@2067
|
25 |
}
|
icculus@2067
|
26 |
|
icculus@2067
|
27 |
/* Initialize SDL */
|
icculus@2067
|
28 |
if ( SDL_Init(0) < 0 ) {
|
icculus@2067
|
29 |
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
|
icculus@2067
|
30 |
return 2;
|
icculus@2067
|
31 |
}
|
icculus@2067
|
32 |
|
icculus@2067
|
33 |
if (strcmp(argv[1], "--hello") == 0) {
|
icculus@2067
|
34 |
hello = 1;
|
icculus@2067
|
35 |
libname = argv[2];
|
icculus@2067
|
36 |
symname = "puts";
|
icculus@2067
|
37 |
} else {
|
icculus@2067
|
38 |
libname = argv[1];
|
icculus@2067
|
39 |
symname = argv[2];
|
icculus@2067
|
40 |
}
|
icculus@2067
|
41 |
|
icculus@2067
|
42 |
lib = SDL_LoadObject(libname);
|
icculus@2067
|
43 |
if (lib == NULL) {
|
icculus@2067
|
44 |
fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n",
|
icculus@2067
|
45 |
libname, SDL_GetError());
|
icculus@2067
|
46 |
retval = 3;
|
icculus@2067
|
47 |
} else {
|
icculus@2067
|
48 |
fn = (fntype) SDL_LoadFunction(lib, symname);
|
icculus@2067
|
49 |
if (fn == NULL) {
|
icculus@2067
|
50 |
fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n",
|
icculus@2067
|
51 |
symname, SDL_GetError());
|
icculus@2067
|
52 |
retval = 4;
|
icculus@2067
|
53 |
} else {
|
icculus@2067
|
54 |
printf("Found %s in %s at %p\n", symname, libname);
|
icculus@2067
|
55 |
if (hello) {
|
icculus@2067
|
56 |
printf("Calling function...\n");
|
icculus@2067
|
57 |
fflush(stdout);
|
icculus@2067
|
58 |
fn(" HELLO, WORLD!\n");
|
icculus@2067
|
59 |
printf("...apparently, we survived. :)\n");
|
icculus@2067
|
60 |
printf("Unloading library...\n");
|
icculus@2067
|
61 |
fflush(stdout);
|
icculus@2067
|
62 |
}
|
icculus@2067
|
63 |
}
|
icculus@2067
|
64 |
SDL_UnloadObject(lib);
|
icculus@2067
|
65 |
}
|
icculus@2067
|
66 |
SDL_Quit();
|
icculus@2067
|
67 |
return(0);
|
icculus@2067
|
68 |
}
|
icculus@2067
|
69 |
|
icculus@2067
|
70 |
|