comparison src/loadso/dlopen/SDL_sysloadso.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 92947e3a18db
children b656e6f09be3
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <dlfcn.h> 30 #include <dlfcn.h>
31 31
32 #include "SDL_loadso.h" 32 #include "SDL_loadso.h"
33 33
34 void *SDL_LoadObject(const char *sofile) 34 void *
35 SDL_LoadObject(const char *sofile)
35 { 36 {
36 void *handle = dlopen(sofile, RTLD_NOW); 37 void *handle = dlopen(sofile, RTLD_NOW);
37 const char *loaderror = (char *)dlerror(); 38 const char *loaderror = (char *) dlerror();
38 if ( handle == NULL ) { 39 if (handle == NULL) {
39 SDL_SetError("Failed loading %s: %s", sofile, loaderror); 40 SDL_SetError("Failed loading %s: %s", sofile, loaderror);
40 } 41 }
41 return(handle); 42 return (handle);
42 } 43 }
43 44
44 void *SDL_LoadFunction(void *handle, const char *name) 45 void *
46 SDL_LoadFunction(void *handle, const char *name)
45 { 47 {
46 void *symbol = dlsym(handle, name); 48 void *symbol = dlsym(handle, name);
47 if ( symbol == NULL ) { 49 if (symbol == NULL) {
48 size_t len = 1+SDL_strlen(name)+1; 50 size_t len = 1 + SDL_strlen(name) + 1;
49 char *_name = SDL_stack_alloc(char, len); 51 char *_name = SDL_stack_alloc(char, len);
50 _name[0] = '_'; 52 _name[0] = '_';
51 SDL_strlcpy(&_name[1], name, len); 53 SDL_strlcpy(&_name[1], name, len);
52 symbol = dlsym(handle, name); 54 symbol = dlsym(handle, name);
53 SDL_stack_free(_name); 55 SDL_stack_free(_name);
54 if ( symbol == NULL ) { 56 if (symbol == NULL) {
55 SDL_SetError("Failed loading %s: %s", name, (const char *)dlerror()); 57 SDL_SetError("Failed loading %s: %s", name,
56 } 58 (const char *) dlerror());
57 } 59 }
58 return(symbol); 60 }
61 return (symbol);
59 } 62 }
60 63
61 void SDL_UnloadObject(void *handle) 64 void
65 SDL_UnloadObject(void *handle)
62 { 66 {
63 if ( handle != NULL ) { 67 if (handle != NULL) {
64 dlclose(handle); 68 dlclose(handle);
65 } 69 }
66 } 70 }
67 71
68 #endif /* SDL_LOADSO_DLOPEN */ 72 #endif /* SDL_LOADSO_DLOPEN */
73 /* vi: set ts=4 sw=4 expandtab: */