Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_dl.c
4561 views
/**************************************************************************1*2* Copyright 2009 VMware, Inc.3* Copyright 1999-2008 Brian Paul4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the8* "Software"), to deal in the Software without restriction, including9* without limitation the rights to use, copy, modify, merge, publish,10* distribute, sub license, and/or sell copies of the Software, and to11* permit persons to whom the Software is furnished to do so, subject to12* the following conditions:13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*22* The above copyright notice and this permission notice (including the23* next paragraph) shall be included in all copies or substantial portions24* of the Software.25*26**************************************************************************/272829#include "pipe/p_config.h"30#include "pipe/p_compiler.h"3132#if defined(PIPE_OS_UNIX)33#include <dlfcn.h>34#endif35#if defined(PIPE_OS_WINDOWS)36#include <windows.h>37#endif3839#include "u_dl.h"40#include "u_pointer.h"414243struct util_dl_library *44util_dl_open(const char *filename)45{46#if defined(PIPE_OS_UNIX)47return (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_LOCAL);48#elif defined(PIPE_OS_WINDOWS)49return (struct util_dl_library *)LoadLibraryA(filename);50#else51return NULL;52#endif53}545556util_dl_proc57util_dl_get_proc_address(struct util_dl_library *library,58const char *procname)59{60#if defined(PIPE_OS_UNIX)61return (util_dl_proc) pointer_to_func(dlsym((void *)library, procname));62#elif defined(PIPE_OS_WINDOWS)63return (util_dl_proc)GetProcAddress((HMODULE)library, procname);64#else65return (util_dl_proc)NULL;66#endif67}686970void71util_dl_close(struct util_dl_library *library)72{73#if defined(PIPE_OS_UNIX)74dlclose((void *)library);75#elif defined(PIPE_OS_WINDOWS)76FreeLibrary((HMODULE)library);77#else78(void)library;79#endif80}818283const char *84util_dl_error(void)85{86#if defined(PIPE_OS_UNIX)87return dlerror();88#elif defined(PIPE_OS_WINDOWS)89return "unknown error";90#else91return "unknown error";92#endif93}949596