Please send us the actual source code so we can check the details. It's
the details that matter, not the high-level description
The procedure below demonstrates the behavior.
int
orgifydir (char** buf, mach_port_t root)
{
error_t err;
data_t dirents;
struct direct d;
mach_msg_type_number_t dataCnt;
err = dir_readdir(root, &dirents, &dataCnt, 0, -1, 0, &amt);
if (err != KERN_SUCCESS)
error(1, 0, "dir_readdir failed with error code %d", err);
while(i++ < amt){
d = *(struct direct*)dirents;
error(0, errno, "name: %s\n", d.d_name);
error(0, errno, "namelen: %d\n", d.d_namlen);
dirents += d.d_reclen;
}
}