annotate test/testloadso.c @ 2098:e554a6547303

Merge of r2554:2995 from branches/SDL-1.2: AvailabilityMacros.h for Mac OS X.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 27 Mar 2007 00:39:03 +0000
parents f16a7d02a176
children 2c835d58faad
rev   line source
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 /* Test program to test dynamic loading with the loadso subsystem.
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 */
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 #include <stdio.h>
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 #include <stdlib.h>
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 #include "SDL.h"
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 typedef int (*fntype)(const char *);
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 int main(int argc, char *argv[])
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 {
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 int retval = 0;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 int hello = 0;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 const char *libname = NULL;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 const char *symname = NULL;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 void *lib = NULL;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 fntype fn = NULL;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 if (argc != 3) {
2068
f16a7d02a176 Merged r2901:2902 from SDL-1.2 branch to trunk: printf stupidity fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 2067
diff changeset
22 const char *app = argv[0];
f16a7d02a176 Merged r2901:2902 from SDL-1.2 branch to trunk: printf stupidity fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 2067
diff changeset
23 fprintf(stderr, "USAGE: %s <library> <functionname>\n", app);
f16a7d02a176 Merged r2901:2902 from SDL-1.2 branch to trunk: printf stupidity fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 2067
diff changeset
24 fprintf(stderr, " %s --hello <lib with puts()>\n", app);
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 return 1;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 }
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 /* Initialize SDL */
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 if ( SDL_Init(0) < 0 ) {
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 return 2;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 }
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 if (strcmp(argv[1], "--hello") == 0) {
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 hello = 1;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 libname = argv[2];
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 symname = "puts";
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 } else {
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 libname = argv[1];
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 symname = argv[2];
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 }
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 lib = SDL_LoadObject(libname);
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 if (lib == NULL) {
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n",
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 libname, SDL_GetError());
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 retval = 3;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 } else {
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 fn = (fntype) SDL_LoadFunction(lib, symname);
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 if (fn == NULL) {
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n",
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 symname, SDL_GetError());
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 retval = 4;
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 } else {
2068
f16a7d02a176 Merged r2901:2902 from SDL-1.2 branch to trunk: printf stupidity fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 2067
diff changeset
55 printf("Found %s in %s at %p\n", symname, libname, fn);
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 if (hello) {
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 printf("Calling function...\n");
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 fflush(stdout);
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 fn(" HELLO, WORLD!\n");
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 printf("...apparently, we survived. :)\n");
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 printf("Unloading library...\n");
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 fflush(stdout);
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 }
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 }
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 SDL_UnloadObject(lib);
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 }
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 SDL_Quit();
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 return(0);
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 }
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71