update readme
[m6w6/ext-psi] / src / types / decl_file.c
index 89c232346603d6bc62f3e928371714efcfce7206..e9366b79789766ceb4142d113436392bd8418307 100644 (file)
  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)
 {
@@ -42,26 +45,25 @@ void psi_decl_file_dtor(struct psi_decl_file *file)
        memset(file, 0, sizeof(*file));
 }
 
-static inline bool validate_lib(struct psi_data *dst, const char *libname, void **dlopened)
+static inline bool validate_lib(struct psi_data *dst, const zend_string *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->val)) {
+               dst->error(dst, NULL, PSI_WARNING, "Library name too long: '%s'",
+                               libname->val);
+               return false;
+       }
+
+       if (!(*dlopened = psi_dlopen(lib))) {
+               dst->error(dst, NULL, PSI_WARNING, "Could not open library '%s': %s",
+                               libname->val, psi_dlerror());
                return false;
        }
 
@@ -71,7 +73,7 @@ static inline bool validate_lib(struct psi_data *dst, const char *libname, void
 bool psi_decl_file_validate(struct psi_data *dst, struct psi_data *src)
 {
        size_t i = 0;
-       char *libname;
+       zend_string *libname;
        void *dlopened;
 
        while (psi_plist_get(src->file.libnames, i++, &libname)) {
@@ -91,12 +93,14 @@ bool psi_decl_file_validate(struct psi_data *dst, struct psi_data *src)
 
 void psi_libs_free(void **dlopened) {
        if (*dlopened) {
-               dlclose(*dlopened);
+               psi_dlclose(*dlopened);
+               *dlopened = NULL;
        }
 }
 
-void psi_names_free(char **name) {
+void psi_names_free(zend_string **name) {
        if (*name) {
-               free(*name);
+               zend_string_release(*name);
+               *name = NULL;
        }
 }