src/dynapi/SDL_dynapi.c
changeset 9305 0c66e0df64f6
parent 8820 0e935d5b193a
child 9619 b94b6d0bff0f
equal deleted inserted replaced
9304:e64d9374f1be 9305:0c66e0df64f6
   204 #endif
   204 #endif
   205 #include <windows.h>
   205 #include <windows.h>
   206 static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
   206 static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
   207 {
   207 {
   208     HANDLE lib = LoadLibraryA(fname);
   208     HANDLE lib = LoadLibraryA(fname);
   209     return lib ? GetProcAddress(lib, sym) : NULL;
   209     void *retval = NULL;
       
   210     if (lib) {
       
   211         retval = GetProcAddress(lib, sym);
       
   212         if (retval == NULL) {
       
   213             FreeLibrary(lib);
       
   214         }
       
   215     }
       
   216     return retval;
   210 }
   217 }
   211 
   218 
   212 #elif defined(__HAIKU__)
   219 #elif defined(__HAIKU__)
   213 #include <os/kernel/image.h>
   220 #include <os/kernel/image.h>
   214 static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
   221 static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
   215 {
   222 {
   216     image_id lib = load_add_on(fname);
   223     image_id lib = load_add_on(fname);
   217     void *retval = NULL;
   224     void *retval = NULL;
   218     if ((lib < 0) || (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR)) {
   225     if (lib >= 0) {
   219         retval = NULL;
   226         if (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR) {
       
   227             unload_add_on(lib);
       
   228             retval = NULL;
       
   229         }
   220     }
   230     }
   221     return retval;
   231     return retval;
   222 }
   232 }
   223 #elif defined(unix) || defined(__unix__) || defined(__APPLE__)
   233 #elif defined(unix) || defined(__unix__) || defined(__APPLE__)
   224 #include <dlfcn.h>
   234 #include <dlfcn.h>
   225 static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
   235 static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
   226 {
   236 {
   227     void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
   237     void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
   228     return lib ? dlsym(lib, sym) : NULL;
   238     void *retval = NULL;
       
   239     if (lib != NULL) {
       
   240         retval = dlsym(lib, sym);
       
   241         if (retval == NULL) {
       
   242             dlclose(lib);
       
   243         }
       
   244     }
       
   245     return retval;
   229 }
   246 }
   230 #else
   247 #else
   231 #error Please define your platform.
   248 #error Please define your platform.
   232 #endif
   249 #endif
   233 
   250