ffi: improve support for functions returning arrays
[m6w6/ext-psi] / psi.d / glob.psi
index 61ada04bb65c7f0f41d9360c0ed8de1fff958d6c..d0c62cbd16a856bfbe13a2afdfbfa0cd23e2b7aa 100644 (file)
@@ -1,18 +1,30 @@
+#include <glob.h>
+
 function psi\glob(string $pattern, int $flags, array &$glob = NULL, callable $errfn = NULL) : int {
        let path = strval($pattern);
        let flags = intval($flags);
-       let err = callback intval($errfn(
-               to_string(errmsg),
-               to_int(errno)
+       let err = callback(
+               epath, 
+               eerrno
+       ) as intval($errfn(
+               to_string(epath),
+               to_int(eerrno)
        ));
-       let buf = &arrval($glob);
-       return to_int(glob);
+       let buf = &arrval($glob,
+               intval($gl_matchc),
+               intval($gl_pathc),
+               intval($gl_offs),
+               intval($gl_flags),
+               &arrval($gl_pathv, 
+                       strval($gl_pathv)
+               )
+       );
+       return glob(path, flags, err, buf) as to_int(glob);
        set $glob = to_array(*buf,
                to_int(gl_matchc),
                to_int(gl_pathc),
                to_int(gl_offs),
                to_int(gl_flags),
-               to_array(gl_pathv, gl_pathc + gl_offs, to_string(gl_pathv))
+               to_array(*gl_pathv, gl_pathc + gl_offs, to_string(*gl_pathv))
        );
-       free globfree(buf);
 }