1 /*-------------------------------------------------------------------------
2 * drawElements Utility Library
3 * ----------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Dynamic link library abstraction.
22 *//*--------------------------------------------------------------------*/
24 #include "deDynamicLibrary.h"
27 #if (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_SYMBIAN) || (DE_OS == DE_OS_IOS) || (DE_OS == DE_OS_QNX)
28 /* Posix implementation. */
32 struct deDynamicLibrary_s
37 deDynamicLibrary* deDynamicLibrary_open (const char* fileName)
39 deDynamicLibrary* library = (deDynamicLibrary*)deCalloc(sizeof(deDynamicLibrary));
43 library->libHandle = dlopen(fileName, RTLD_LAZY);
44 if (!library->libHandle)
53 void deDynamicLibrary_close (deDynamicLibrary* library)
55 if (library && library->libHandle)
56 dlclose(library->libHandle);
60 deFunctionPtr deDynamicLibrary_getFunction (const deDynamicLibrary* library, const char* symbolName)
62 /* C forbids direct cast from object pointer to function pointer */
65 deFunctionPtr funcPtr;
69 DE_ASSERT(library && library->libHandle && symbolName);
70 ptr.objPtr = dlsym(library->libHandle, symbolName);
74 #elif (DE_OS == DE_OS_WIN32)
75 /* Win32 implementation. */
77 #define WIN32_LEAN_AND_MEAN
81 struct deDynamicLibrary_s
86 deDynamicLibrary* deDynamicLibrary_open (const char* fileName)
88 deDynamicLibrary* library = (deDynamicLibrary*)deCalloc(sizeof(deDynamicLibrary));
92 library->handle = LoadLibrary(fileName);
102 void deDynamicLibrary_close (deDynamicLibrary* library)
104 if (library && library->handle)
105 FreeLibrary(library->handle);
109 deFunctionPtr deDynamicLibrary_getFunction (const deDynamicLibrary* library, const char* symbolName)
111 DE_ASSERT(library && library->handle && symbolName);
112 return (deFunctionPtr)GetProcAddress(library->handle, symbolName);
116 # error deDynamicLibrary is not implemented on this OS