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

Latest commit

 

History

History
70 lines (61 loc) · 1.76 KB

testloadso.c

File metadata and controls

70 lines (61 loc) · 1.76 KB
 
1
2
3
4
5
6
7
8
9
/* Test program to test dynamic loading with the loadso subsystem.
*/
#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"
Jun 14, 2007
Jun 14, 2007
10
typedef int (*fntype) (const char *);
Jun 14, 2007
Jun 14, 2007
12
13
int
main(int argc, char *argv[])
Jun 14, 2007
Jun 14, 2007
15
16
17
18
19
20
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
22
23
24
25
26
27
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
29
30
31
32
33
/* 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
35
36
37
38
39
40
41
42
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
44
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
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);