Path: blob/master/thirdparty/sdl/loadso/dlopen/SDL_sysloadso.c
9904 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"2122#ifdef SDL_LOADSO_DLOPEN2324/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */25// System dependent library loading routines2627#include <stdio.h>28#include <dlfcn.h>2930#ifdef SDL_VIDEO_DRIVER_UIKIT31#include "../../video/uikit/SDL_uikitvideo.h"32#endif3334SDL_SharedObject *SDL_LoadObject(const char *sofile)35{36void *handle;37const char *loaderror;3839#ifdef SDL_VIDEO_DRIVER_UIKIT40if (!UIKit_IsSystemVersionAtLeast(8.0)) {41SDL_SetError("SDL_LoadObject requires iOS 8+");42return NULL;43}44#endif4546handle = dlopen(sofile, RTLD_NOW | RTLD_LOCAL);47loaderror = dlerror();48if (!handle) {49SDL_SetError("Failed loading %s: %s", sofile, loaderror);50}51return (SDL_SharedObject *) handle;52}5354SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)55{56void *symbol = dlsym(handle, name);57if (!symbol) {58// prepend an underscore for platforms that need that.59bool isstack;60size_t len = SDL_strlen(name) + 1;61char *_name = SDL_small_alloc(char, len + 1, &isstack);62_name[0] = '_';63SDL_memcpy(&_name[1], name, len);64symbol = dlsym(handle, _name);65SDL_small_free(_name, isstack);66if (!symbol) {67//SDL_SetError("Failed loading %s: %s", name,68// (const char *)dlerror());69}70}71return symbol;72}7374void SDL_UnloadObject(SDL_SharedObject *handle)75{76if (handle) {77dlclose(handle);78}79}8081#endif // SDL_LOADSO_DLOPEN828384