FreeSWITCH API Documentation  1.7.0
Functions
switch_dso.c File Reference
#include <switch.h>
#include "switch_dso.h"
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
+ Include dependency graph for switch_dso.c:

Go to the source code of this file.

Functions

void switch_dso_destroy (switch_dso_lib_t *lib)
 
switch_dso_lib_t switch_dso_open (const char *path, int global, char **err)
 
switch_dso_func_t switch_dso_func_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)
 

Function Documentation

void* switch_dso_data_sym ( switch_dso_lib_t  lib,
const char *  sym,
char **  err 
)

Definition at line 126 of file switch_dso.c.

Referenced by switch_loadable_module_load_file().

127 {
128  void *addr = dlsym(lib, sym);
129  if (!addr) {
130  char *err_str = NULL;
131  dlerror();
132 
133  if (!(addr = dlsym(lib, sym))) {
134  err_str = (char *)dlerror();
135  }
136 
137  if (err_str) {
138  *err = strdup(err_str);
139  }
140  }
141  return addr;
142 }
void switch_dso_destroy ( switch_dso_lib_t lib)

Definition at line 87 of file switch_dso.c.

Referenced by do_shutdown(), and switch_loadable_module_load_file().

88 {
89  if (lib && *lib) {
90  dlclose(*lib);
91  *lib = NULL;
92  }
93 }
switch_dso_func_t switch_dso_func_sym ( switch_dso_lib_t  lib,
const char *  sym,
char **  err 
)

Definition at line 117 of file switch_dso.c.

References switch_dso_func_t.

118 {
119  void *func = dlsym(lib, sym);
120  if (!func) {
121  *err = strdup(dlerror());
122  }
123  return (switch_dso_func_t) (intptr_t) func;
124 }
SWITCH_BEGIN_EXTERN_C typedef int(* switch_dso_func_t)(void)
Definition: switch_dso.h:26
switch_dso_lib_t switch_dso_open ( const char *  path,
int  global,
char **  err 
)

Definition at line 95 of file switch_dso.c.

Referenced by switch_loadable_module_load_file().

96 {
97  void *lib;
98 
99  if (global) {
100  lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
101  } else {
102  lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
103  }
104 
105  if (lib == NULL) {
106  const char *dlerr = dlerror();
107  /* Work around broken uclibc returning NULL on both dlopen() and dlerror() */
108  if (dlerr) {
109  *err = strdup(dlerr);
110  } else {
111  *err = strdup("Unknown error");
112  }
113  }
114  return lib;
115 }