2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
29 /* System dependent library loading routines */
32 #if defined(USE_DLOPEN)
36 #elif defined(__BEOS__)
37 # include <be/kernel/image.h>
38 #elif defined(macintosh)
41 # include <CodeFragments.h>
44 /*#error Unsupported dynamic link environment*/
45 #endif /* system type */
47 #include "SDL_error.h"
48 #include "SDL_loadso.h"
50 void *SDL_LoadObject(const char *sofile)
53 const char *loaderror = "SDL_LoadObject() not implemented";
54 #if defined(USE_DLOPEN)
56 handle = dlopen(sofile, RTLD_NOW);
57 loaderror = (char *)dlerror();
62 handle = (void *)LoadLibrary(sofile);
64 /* Generate an error message if all loads failed */
65 if ( handle == NULL ) {
66 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
67 FORMAT_MESSAGE_FROM_SYSTEM),
69 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
70 errbuf, SDL_TABLESIZE(errbuf), NULL);
73 #elif defined(__BEOS__)
77 library_id = load_add_on(sofile);
78 if ( library_id == B_ERROR ) {
79 loaderror = "BeOS error";
81 handle = (void *)(library_id);
83 #elif defined(macintosh)
85 CFragConnectionID library_id;
91 strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
92 psofile[SDL_TABLESIZE(psofile)-1] = '\0';
93 error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
94 kLoadCFrag, &library_id, &mainAddr, errName);
98 case cfragNoLibraryErr:
99 loaderror = "Library not found";
101 case cfragUnresolvedErr:
102 loaderror = "Unabled to resolve symbols";
104 case cfragNoPrivateMemErr:
105 case cfragNoClientMemErr:
106 loaderror = "Out of memory";
109 loaderror = "Unknown Code Fragment Manager error";
112 if ( loaderror == NULL ) {
113 handle = (void *)(library_id);
115 #endif /* system type */
117 if ( handle == NULL ) {
118 SDL_SetError("Failed loading %s: %s", sofile, loaderror);
123 void *SDL_LoadFunction(void *handle, const char *name)
126 const char *loaderror = "SDL_LoadFunction not implemented";
127 #if defined(USE_DLOPEN)
129 symbol = dlsym(handle, name);
130 if ( symbol == NULL ) {
131 loaderror = (char *)dlerror();
137 symbol = (void *)GetProcAddress((HMODULE)handle, name);
138 if ( symbol == NULL ) {
139 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
140 FORMAT_MESSAGE_FROM_SYSTEM),
141 NULL, GetLastError(),
142 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
143 errbuf, SDL_TABLESIZE(errbuf), NULL);
146 #elif defined(__BEOS__)
148 image_id library_id = (image_id)handle;
149 if ( get_image_symbol(library_id,
150 name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR ) {
151 loaderror = "Symbol not found";
153 #elif defined(macintosh)
155 CFragSymbolClass class;
156 CFragConnectionID library_id = (CFragConnectionID)handle;
159 strncpy(pname, name, SDL_TABLESIZE(pname));
160 pname[SDL_TABLESIZE(pname)-1] = '\0';
161 if ( FindSymbol(library_id, C2PStr(pname),
162 (char **)&symbol, &class) != noErr ) {
163 loaderror = "Symbol not found";
165 #endif /* system type */
167 if ( symbol == NULL ) {
168 SDL_SetError("Failed loading %s: %s", name, loaderror);
173 void SDL_UnloadObject(void *handle)
175 if ( handle == NULL ) {
178 #if defined(USE_DLOPEN)
183 FreeLibrary((HMODULE)handle);
184 #elif defined(__BEOS__)
186 image_id library_id = (image_id)handle;
187 unload_add_on(library_id);
188 #elif defined(macintosh)
190 CFragConnectionID library_id = (CFragConnectionID)handle;
191 CloseConnection(library_id);
192 #endif /* system type */