This should be doable with some combination of fdopendir(3) and readdir(3). I'm not sure how to avoid leaking memory through the returned DIR pointer and any memory allocated with by readdir(3). This is usually free'd by closedir(3), which we can't use without closing the underlying file.
It should be OK to use free() on the return value of fdopendir, and stick to the uglier readdir_r(3) interface. I can definitely see why Russ went with the simpler system-specific interfaces on this. David On Sat, Apr 8, 2017, at 02:46 AM, Ori Bernstein wrote: > On Sat, 8 Apr 2017 15:21:47 +0900, arisawa <karis...@gmail.com> wrote: > > > but how to? > > > > unix doesn’t have something like fdreaddir(int fd). > > my guess: russ unwillingly used a low level function such as > > int getdirentries(int fd, char *buf, int nbytes, long *basep). > > > > readdirall() might be OK in regular usage. > > I don't use OSX regularly, although I do maintain the syscall > layer for Myrddin on it. > > Getdirentries64 exists, and rudimentary testing doesn't show > any difficulties with using it. > > -- > Ori Bernstein >