annotate src/SDL_loadso.c @ 1014:cfcb2e1c36eb release-1.2.8

Added change log notes
author Sam Lantinga <slouken@libsdl.org>
date Wed, 15 Dec 2004 01:02:20 +0000
parents 0c3e00cc9580
children cf6133247d34
rev   line source
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 708
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #ifdef SAVE_RCSID
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 static char rcsid =
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 "@(#) $Id$";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #endif
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 /* System dependent library loading routines */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <stdio.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 # include <dlfcn.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 # include <windows.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 # include <be/kernel/image.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 # include <string.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 # include <Strings.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 # include <CodeFragments.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 # include <Errors.h>
651
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
43 #elif defined(__MINT__) && defined(ENABLE_LDG)
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
44 # include <gem.h>
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
45 # include <ldg.h>
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #else
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 /*#error Unsupported dynamic link environment*/
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49
296
fab1ddc4d7bf Removed the API changes to preserve SDL 1.2 stability
Sam Lantinga <slouken@libsdl.org>
parents: 294
diff changeset
50 #include "SDL_types.h"
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #include "SDL_error.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #include "SDL_loadso.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 void *SDL_LoadObject(const char *sofile)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 void *handle = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 const char *loaderror = "SDL_LoadObject() not implemented";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 #if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 handle = dlopen(sofile, RTLD_NOW);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 loaderror = (char *)dlerror();
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 #elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 char errbuf[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 handle = (void *)LoadLibrary(sofile);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 /* Generate an error message if all loads failed */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 FORMAT_MESSAGE_FROM_SYSTEM),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 NULL, GetLastError(),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 errbuf, SDL_TABLESIZE(errbuf), NULL);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 loaderror = errbuf;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 #elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 image_id library_id;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 library_id = load_add_on(sofile);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 if ( library_id == B_ERROR ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 loaderror = "BeOS error";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 } else {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 handle = (void *)(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 #elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 CFragConnectionID library_id;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 Ptr mainAddr;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 Str255 errName;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 OSErr error;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 char psofile[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 psofile[SDL_TABLESIZE(psofile)-1] = '\0';
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 kLoadCFrag, &library_id, &mainAddr, errName);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 switch (error) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 case noErr:
774
0c3e00cc9580 Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
101 loaderror = NULL;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 case cfragNoLibraryErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 loaderror = "Library not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 case cfragUnresolvedErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 loaderror = "Unabled to resolve symbols";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 case cfragNoPrivateMemErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 case cfragNoClientMemErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 loaderror = "Out of memory";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 default:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 loaderror = "Unknown Code Fragment Manager error";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 if ( loaderror == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 handle = (void *)(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 }
651
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
120 #elif defined(__MINT__) && defined(ENABLE_LDG)
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
121 /* * */
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
122 handle = (void *)ldg_open((char *)sofile, ldg_global);
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 #endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 SDL_SetError("Failed loading %s: %s", sofile, loaderror);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 return(handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 void *SDL_LoadFunction(void *handle, const char *name)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 void *symbol = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 const char *loaderror = "SDL_LoadFunction not implemented";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 #if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 symbol = dlsym(handle, name);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 loaderror = (char *)dlerror();
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 #elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 char errbuf[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 symbol = (void *)GetProcAddress((HMODULE)handle, name);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 FORMAT_MESSAGE_FROM_SYSTEM),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 NULL, GetLastError(),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 errbuf, SDL_TABLESIZE(errbuf), NULL);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 loaderror = errbuf;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 #elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 image_id library_id = (image_id)handle;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 if ( get_image_symbol(library_id,
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 loaderror = "Symbol not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 #elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 CFragSymbolClass class;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 CFragConnectionID library_id = (CFragConnectionID)handle;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 char pname[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 strncpy(pname, name, SDL_TABLESIZE(pname));
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 pname[SDL_TABLESIZE(pname)-1] = '\0';
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 if ( FindSymbol(library_id, C2PStr(pname),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 (char **)&symbol, &class) != noErr ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 loaderror = "Symbol not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 }
651
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
173 #elif defined(__MINT__) && defined(ENABLE_LDG)
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
174 /* * */
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
175 symbol = (void *)ldg_find((char *)name, (LDG *)handle);
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 #endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 SDL_SetError("Failed loading %s: %s", name, loaderror);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 return(symbol);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 void SDL_UnloadObject(void *handle)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 {
336
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
186 #if defined(__BEOS__)
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
187 image_id library_id;
707
c67d4fb10a45 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 651
diff changeset
188 #elif defined(macintosh)
c67d4fb10a45 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 651
diff changeset
189 CFragConnectionID library_id;
336
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
190 #endif
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 return;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 #if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 dlclose(handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 #elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 FreeLibrary((HMODULE)handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 #elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 /* * */
336
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
202 library_id = (image_id)handle;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 unload_add_on(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 #elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 /* * */
707
c67d4fb10a45 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 651
diff changeset
206 library_id = (CFragConnectionID)handle;
708
d0d50f2b044c Fixed building SDL_loadso.c on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents: 707
diff changeset
207 CloseConnection(&library_id);
651
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
208 #elif defined(__MINT__) && defined(ENABLE_LDG)
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
209 /* * */
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
210 ldg_close((LDG *)handle, ldg_global);
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 #endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 }