Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
71 lines (62 loc) · 1.78 KB

testloadso.c

File metadata and controls

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