Thanks, that's a start at least. I see what you're saying, but I can't seem to get it to work for me.
I update my types as follows
(define-ftype char* (* char))
(define-ftype char** (* char*))
(define-ftype glob_t
(struct
[gl_pathc size_t]
[gl_pathv char**]
[gl_offs size_t]))
Then after getting the glob_t pointer ran code like this
(define gp (ftype-&ref glob_t (gl_pathv) g))
Then to reference the string itself
(ftype-pointer->sexpr (ftype-&ref char** () gp 0))
This works only for an index of 0, but then for subsequent index values it returns either "null" or "invalid". At least this is what I gathered from your explanation I should be doing. If I'm not understanding then a code example would be really helpful.
I will say that I found a workaround to this problem where I write some C code like the following to retrieve an entry at an index in the array.
#include <stdio.h>
#include <glob.h>
extern char *get_path_idx(glob_t *obj, int idx);
char *get_path_idx(glob_t *obj, int idx)
{
if (idx > obj->gl_pathc) return NULL;
return obj->gl_pathv[idx];
}
And in scheme added this code
(define (glob-paths g)
(let ((count (ftype-ref glob_t (gl_pathc) g)))
(define (add-glob-path glob acc num total)
(if (< num total)
(add-path glob (cons (get-path-idx glob num) acc) (+ num 1) total)
acc))
(add-glob-path g '() 0 count)))
So this actually returns all the entries which at least proves that the entries are allocated correctly, just that scheme is somehow not representing it properly. I'd still really like to understand how I'm going wrong with the pure scheme implementation.
Best Regards,
Matt