OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
-#include "php_psi_stdinc.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
#include "data.h"
-
-#include <dlfcn.h>
+#include "dl.h"
void psi_decl_file_dtor(struct psi_decl_file *file)
{
psi_plist_free(file->dlopened);
}
if (file->filename) {
- free(file->filename);
+ zend_string_release(file->filename);
}
memset(file, 0, sizeof(*file));
}
static inline bool validate_lib(struct psi_data *dst, const char *libname, void **dlopened)
{
- char lib[MAXPATHLEN];
- size_t len;
+ char lib[PATH_MAX];
+ size_t len = PATH_MAX;
if (!libname) {
/* FIXME: assume stdlib */
return true;
- } else if (!strchr(libname, '/')) {
- len = snprintf(lib, MAXPATHLEN, "lib%s.%s", libname, PHP_PSI_SHLIB_SUFFIX);
- if (MAXPATHLEN == len) {
- dst->error(dst, NULL, PSI_WARNING, "Library name too long: '%s'",
- libname);
- }
- lib[len] = 0;
- libname = lib;
}
- if (!(*dlopened = dlopen(libname, RTLD_LAZY | RTLD_LOCAL))) {
- dst->error(dst, NULL, PSI_WARNING, "Could not open library '%s': %s.",
- libname, dlerror());
+
+ if (PATH_MAX == psi_dlname(&lib, &len, libname)) {
+ dst->error(dst, NULL, PSI_WARNING, "Library name too long: '%s'",
+ libname);
+ return false;
+ }
+
+ if (!(*dlopened = psi_dlopen(lib))) {
+ dst->error(dst, NULL, PSI_WARNING, "Could not open library '%s': %s",
+ libname, psi_dlerror());
return false;
}
return false;
}
- libname = strdup(libname);
dst->file.libnames = psi_plist_add(dst->file.libnames, &libname);
dst->file.dlopened = psi_plist_add(dst->file.dlopened, &dlopened);
}
if (src->file.filename) {
- dst->file.filename = strdup(src->file.filename);
+ dst->file.filename = zend_string_copy(src->file.filename);
}
return true;
}
void psi_libs_free(void **dlopened) {
if (*dlopened) {
- dlclose(*dlopened);
+ psi_dlclose(*dlopened);
}
}