nix
nix copied to clipboard
readdir needs to call rewinddir
trafficstars
At least on BSD, and it looks like in some circumstances on Linux too. Quoting the NetBSD man page:
fdopendir(fd)
The fdopendir() function associates a directory stream with the
directory file descriptor fd. The file offset associated with fd at
the time of the call determines which entries are returned.
Are you suggesting that Dir::from_fd should always rewind the dir, or that it should have an optional method for that? I don't think that always rewinding is necessarily the right option.
So the scenario is this:
- open fd P, do something like openat() on P, which shifts the read pointer.
- opendirat(P) - gets a DIR* but the read pointer for P is not at 0
- readdir(P) - content is missed
Yeah, in that above case I'd say that moving the read pointer is deliberate. We could have an optional method to rewinddir, but it shouldn't be mandatory. Basically, if the user gives us a raw file descriptor, we have to assume that they know what they're doing with it.