zenilib: zenilib/jni/external/sdl/src/loadso/dlopen/SDL_sysloadso.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_sysloadso.c
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 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_config.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 void *
34 SDL_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
44 void *
45 SDL_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
64 void
65 SDL_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: */
NULL
#define NULL
Definition: ftobjs.h:61
SDL_stack_free
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:227
name
EGLImageKHR EGLint * name
Definition: eglext.h:284
len
GLenum GLsizei len
Definition: glew.h:7035
SDL_config.h
SDL_LoadObject
DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile)
SDL_strlcpy
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
Definition: SDL_string.c:448
SDL_UnloadObject
DECLSPEC void SDLCALL SDL_UnloadObject(void *handle)
SDL_SetError
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
SDL_strlen
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
Definition: SDL_string.c:389
SDL_loadso.h
SDL_stack_alloc
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:226
handle
EGLImageKHR EGLint EGLint * handle
Definition: eglext.h:284
SDL_LoadFunction
DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle, const char *name)