提交 5bc6dc2c authored 作者: Michael Jerris's avatar Michael Jerris

line endings

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10300 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 a193d843
/* /*
* Cross Platform dso/dll load abstraction * Cross Platform dso/dll load abstraction
* Copyright(C) 2008 Michael Jerris * Copyright(C) 2008 Michael Jerris
* *
* You may opt to use, copy, modify, merge, publish, distribute and/or sell * You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is * copies of the Software, and permit persons to whom the Software is
* furnished to do so. * furnished to do so.
* *
* This work is provided under this license on an "as is" basis, without warranty of any kind, * This work is provided under this license on an "as is" basis, without warranty of any kind,
* either expressed or implied, including, without limitation, warranties that the covered code * either expressed or implied, including, without limitation, warranties that the covered code
* is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
* risk as to the quality and performance of the covered code is with you. Should any covered * risk as to the quality and performance of the covered code is with you. Should any covered
* code prove defective in any respect, you (not the initial developer or any other contributor) * code prove defective in any respect, you (not the initial developer or any other contributor)
* assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
* constitutes an essential part of this license. No use of any covered code is authorized hereunder * constitutes an essential part of this license. No use of any covered code is authorized hereunder
* except under this disclaimer. * except under this disclaimer.
* *
*/ */
#include <switch.h> #include <switch.h>
#include "switch_dso.h" #include "switch_dso.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef WIN32 #ifdef WIN32
void switch_dso_destroy(switch_dso_lib_t *lib) { void switch_dso_destroy(switch_dso_lib_t *lib) {
if (lib && *lib) { if (lib && *lib) {
FreeLibrary(*lib); FreeLibrary(*lib);
*lib = NULL; *lib = NULL;
} }
} }
switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) { switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
HINSTANCE lib; HINSTANCE lib;
lib = LoadLibraryEx(path, NULL, 0); lib = LoadLibraryEx(path, NULL, 0);
if (!lib) { if (!lib) {
LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
} }
if (!lib) { if (!lib) {
DWORD error = GetLastError(); DWORD error = GetLastError();
*err = switch_mprintf("dll open error [%ul]\n", error); *err = switch_mprintf("dll open error [%ul]\n", error);
} }
return lib; return lib;
} }
switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) { switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
FARPROC func = GetProcAddress(lib, sym); FARPROC func = GetProcAddress(lib, sym);
if (!func) { if (!func) {
DWORD error = GetLastError(); DWORD error = GetLastError();
*err = switch_mprintf("dll sym error [%ul]\n", error); *err = switch_mprintf("dll sym error [%ul]\n", error);
} }
return (switch_dso_func_t)func; return (switch_dso_func_t)func;
} }
void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) { void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
FARPROC addr = GetProcAddress(lib, sym); FARPROC addr = GetProcAddress(lib, sym);
if (!addr) { if (!addr) {
DWORD error = GetLastError(); DWORD error = GetLastError();
*err = switch_mprintf("dll sym error [%ul]\n", error); *err = switch_mprintf("dll sym error [%ul]\n", error);
} }
return (void *)(intptr_t)addr; return (void *)(intptr_t)addr;
} }
#else #else
/* /*
** {======================================================================== ** {========================================================================
** This is an implementation of loadlib based on the dlfcn interface. ** This is an implementation of loadlib based on the dlfcn interface.
** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, ** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least ** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least
** as an emulation layer on top of native functions. ** as an emulation layer on top of native functions.
** ========================================================================= ** =========================================================================
*/ */
#include <dlfcn.h> #include <dlfcn.h>
void switch_dso_destroy(switch_dso_lib_t *lib) { void switch_dso_destroy(switch_dso_lib_t *lib) {
if (lib && *lib) { if (lib && *lib) {
dlclose(*lib); dlclose(*lib);
*lib = NULL; *lib = NULL;
} }
} }
switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) { switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
void *lib; void *lib;
if (global) { if (global) {
lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL); lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
} else { } else {
lib = dlopen(path, RTLD_NOW | RTLD_LOCAL); lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
} }
if (lib == NULL) { if (lib == NULL) {
*err = strdup(dlerror()); *err = strdup(dlerror());
} }
return lib; return lib;
} }
switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) { switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
void *func = dlsym(lib, sym); void *func = dlsym(lib, sym);
if (!func) { if (!func) {
*err = strdup(dlerror()); *err = strdup(dlerror());
} }
return (switch_dso_func_t)(intptr_t)func; return (switch_dso_func_t)(intptr_t)func;
} }
void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) { void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
void *addr = dlsym(lib, sym); void *addr = dlsym(lib, sym);
if (!addr) { if (!addr) {
*err = strdup(dlerror()); *err = strdup(dlerror());
} }
return addr; return addr;
} }
#endif #endif
/* }====================================================== */ /* }====================================================== */
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c
* indent-tabs-mode:t * indent-tabs-mode:t
* tab-width:4 * tab-width:4
* c-basic-offset:4 * c-basic-offset:4
* End: * End:
* For VIM: * For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 * vim:set softtabstop=4 shiftwidth=4 tabstop=4
*/ */
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论