* Load the specified dynamic-link library file, and look for a function * named funcname in it. * * If the function is not found, we raise an error if signalNotFound is true, * else return NULL. Note that errors in loading the library * will provoke ereport() regardless of signalNotFound. * * If filehandle is not NULL, then *filehandle will be set to a handle * identifying the library fil
| 105 | * at less cost than repeating load_external_function. |
| 106 | */ |
| 107 | void * |
| 108 | load_external_function(const char *filename, const char *funcname, |
| 109 | bool signalNotFound, void **filehandle) |
| 110 | { |
| 111 | char *fullname; |
| 112 | void *lib_handle; |
| 113 | void *retval; |
| 114 | |
| 115 | /* Expand the possibly-abbreviated filename to an exact path name */ |
| 116 | fullname = expand_dynamic_library_name(filename); |
| 117 | |
| 118 | /* Load the shared library, unless we already did */ |
| 119 | lib_handle = internal_load_library(fullname); |
| 120 | |
| 121 | /* Return handle if caller wants it */ |
| 122 | if (filehandle) |
| 123 | *filehandle = lib_handle; |
| 124 | |
| 125 | /* Look up the function within the library. */ |
| 126 | retval = dlsym(lib_handle, funcname); |
| 127 | |
| 128 | if (retval == NULL && signalNotFound) |
| 129 | ereport(ERROR, |
| 130 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 131 | errmsg("could not find function \"%s\" in file \"%s\"", |
| 132 | funcname, fullname))); |
| 133 | |
| 134 | pfree(fullname); |
| 135 | return retval; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * This function loads a shlib file without looking up any particular |
no test coverage detected