| 160 | */ |
| 161 | |
| 162 | void *msGetSymbol( const char * pszLibrary, const char * pszSymbolName ) |
| 163 | { |
| 164 | void *pLibrary; |
| 165 | void *pSymbol; |
| 166 | |
| 167 | pLibrary = dlopen(pszLibrary, RTLD_LAZY); |
| 168 | if( pLibrary == NULL ) |
| 169 | { |
| 170 | msSetError(MS_MISCERR, |
| 171 | "Dynamic loading failed: %s", |
| 172 | "msGetSymbol()", dlerror()); |
| 173 | return NULL; |
| 174 | } |
| 175 | |
| 176 | pSymbol = dlsym( pLibrary, pszSymbolName ); |
| 177 | |
| 178 | #if (defined(__APPLE__) && defined(__MACH__)) |
| 179 | /* On mach-o systems, C symbols have a leading underscore and depending |
| 180 | * on how dlcompat is configured it may or may not add the leading |
| 181 | * underscore. So if dlsym() fails add an underscore and try again. |
| 182 | */ |
| 183 | if( pSymbol == NULL ) |
| 184 | { |
| 185 | char withUnder[strlen(pszSymbolName) + 2]; |
| 186 | withUnder[0] = '_'; withUnder[1] = 0; |
| 187 | strcat(withUnder, pszSymbolName); |
| 188 | pSymbol = dlsym( pLibrary, withUnder ); |
| 189 | } |
| 190 | #endif |
| 191 | |
| 192 | if( pSymbol == NULL ) |
| 193 | { |
| 194 | msSetError(MS_MISCERR, |
| 195 | "Dynamic loading failed: %s", |
| 196 | "msGetSymbol()", dlerror()); |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | return( pSymbol ); |
| 201 | } |
| 202 | |
| 203 | #endif /* def __unix__ && defined(HAVE_DLFCN_H) */ |
| 204 |
no test coverage detected