Skip to contentSkip to conversation

What's the equivalent of readdirat()?

DISCUSSION Rob Landley 2 participants 2 messages Feb 18, 2008 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

I'm moving some code to use openat() and friends, but there doesn't appear to be a readdirat().

The problem is that readdir(3) takes a path from cwd. The syscall readdir(2) takes a file descriptor, but the man page for readdir(2) says it was supplanted by getdents. The getdents man page says that's an internal syscall that glibc doesn't even bother to _wrap_, and points me back at readdir(3) which still takes a path from cwd...

None of the "see also" stuff at the end of any of these pages is useful.

Any hints?

Rob

Signature · 2 lines
"One of my most productive days was throwing away 1000 lines of code."
  - Ken Thompson.
#1 lore raw
Quoted 3 lines · Rob Landley

I'm moving some code to use openat() and friends, but there doesn't appear to be a readdirat().

The problem is that readdir(3) takes a path from cwd.

No, it doesn't. readdir() takes an existing DIR pointer, that was previously returned by opendir(3).

You will note that the opendir(3) man page also described an alternative fdopendir() function, which in conjunction with openat(3) will do what you want.