SDL_sysloadso.c (2247B)
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "../../SDL_internal.h" 22 23#ifdef SDL_LOADSO_DLOPEN 24 25/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 26/* System dependent library loading routines */ 27 28#include <stdio.h> 29#include <dlfcn.h> 30 31#include "SDL_loadso.h" 32 33void * 34SDL_LoadObject(const char *sofile) 35{ 36 void *handle = dlopen(sofile, RTLD_NOW|RTLD_LOCAL); 37 const char *loaderror = (char *) dlerror(); 38 if (handle == NULL) { 39 SDL_SetError("Failed loading %s: %s", sofile, loaderror); 40 } 41 return (handle); 42} 43 44void * 45SDL_LoadFunction(void *handle, const char *name) 46{ 47 void *symbol = dlsym(handle, name); 48 if (symbol == NULL) { 49 /* append an underscore for platforms that need that. */ 50 size_t len = 1 + SDL_strlen(name) + 1; 51 char *_name = SDL_stack_alloc(char, len); 52 _name[0] = '_'; 53 SDL_strlcpy(&_name[1], name, len); 54 symbol = dlsym(handle, _name); 55 SDL_stack_free(_name); 56 if (symbol == NULL) { 57 SDL_SetError("Failed loading %s: %s", name, 58 (const char *) dlerror()); 59 } 60 } 61 return (symbol); 62} 63 64void 65SDL_UnloadObject(void *handle) 66{ 67 if (handle != NULL) { 68 dlclose(handle); 69 } 70} 71 72#endif /* SDL_LOADSO_DLOPEN */ 73 74/* vi: set ts=4 sw=4 expandtab: */