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

Latest commit

 

History

History
82 lines (71 loc) · 2.17 KB

testloadso.c

File metadata and controls

82 lines (71 loc) · 2.17 KB
 
Apr 8, 2011
Apr 8, 2011
1
2
3
4
5
6
7
8
9
10
11
/*
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
Oct 4, 2009
Oct 4, 2009
13
/* Test program to test dynamic loading with the loadso subsystem.
14
15
16
17
*/
#include <stdio.h>
#include <stdlib.h>
Oct 4, 2009
Oct 4, 2009
18
#include <string.h>
19
20
21
#include "SDL.h"
Jun 14, 2007
Jun 14, 2007
22
typedef int (*fntype) (const char *);
Jun 14, 2007
Jun 14, 2007
24
25
int
main(int argc, char *argv[])
Jun 14, 2007
Jun 14, 2007
27
28
29
30
31
32
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
34
35
36
37
38
39
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
41
42
43
44
45
/* 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
47
48
49
50
51
52
53
54
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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);