src/loadso/dlopen/SDL_sysloadso.c
author Sam Lantinga
Wed, 18 Jan 2017 12:19:57 -0800
changeset 10821 b0b8395f5cf9
parent 10737 3406a0f8b041
child 11552 2603f41d6a7e
permissions -rw-r--r--
Removed unused variable
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2017 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 
    33 #if SDL_VIDEO_DRIVER_UIKIT
    34 #include "../../video/uikit/SDL_uikitvideo.h"
    35 #endif
    36 
    37 void *
    38 SDL_LoadObject(const char *sofile)
    39 {
    40     void *handle;
    41     const char *loaderror;
    42 
    43 #if SDL_VIDEO_DRIVER_UIKIT
    44     if (!UIKit_IsSystemVersionAtLeast(8.0)) {
    45         SDL_SetError("SDL_LoadObject requires iOS 8+");
    46         return NULL;
    47     }
    48 #endif
    49 
    50     handle = dlopen(sofile, RTLD_NOW|RTLD_LOCAL);
    51     loaderror = (char *) dlerror();
    52     if (handle == NULL) {
    53         SDL_SetError("Failed loading %s: %s", sofile, loaderror);
    54     }
    55     return (handle);
    56 }
    57 
    58 void *
    59 SDL_LoadFunction(void *handle, const char *name)
    60 {
    61     void *symbol = dlsym(handle, name);
    62     if (symbol == NULL) {
    63         /* append an underscore for platforms that need that. */
    64         size_t len = 1 + SDL_strlen(name) + 1;
    65         char *_name = SDL_stack_alloc(char, len);
    66         _name[0] = '_';
    67         SDL_strlcpy(&_name[1], name, len);
    68         symbol = dlsym(handle, _name);
    69         SDL_stack_free(_name);
    70         if (symbol == NULL) {
    71             SDL_SetError("Failed loading %s: %s", name,
    72                          (const char *) dlerror());
    73         }
    74     }
    75     return (symbol);
    76 }
    77 
    78 void
    79 SDL_UnloadObject(void *handle)
    80 {
    81     if (handle != NULL) {
    82         dlclose(handle);
    83     }
    84 }
    85 
    86 #endif /* SDL_LOADSO_DLOPEN */
    87 
    88 /* vi: set ts=4 sw=4 expandtab: */