konstantin
konstantin

Reputation: 69

POSIX seekdir() and telldir() behaviour after target folder modification

consider the following task :

1) read a target directory contents, pass each found dirent structure to some filter function and remember filtered elements somehow for the later processing

2) some time later, iterate through the filtered elements and process them (do some I/O)

The most obvious way is to save names of sub-directories.
However, I want to keep memory usage to the minimum and to avoid additional I/O.

According to POSIX manuals, I can save position of each directory entry using telldir() and restore them later using seekdir(). To keep these positions valid, I have to keep target directory opened and to not use rewinddir() call.
Keeping a directory stream open and storing a list of dir positions(long int`s) seems to be an appropriate solution.
However, it is unclear whether stored positions remain valid after folder modification. I didn`t found any comments on these conditions in the POSIX standard.

It is easy to test and find out the answer on these questions for the particular system, but I would like to know what standards say on this topic

Thank you

Upvotes: 5

Views: 1328

Answers (1)

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215173

Until you call rewinddir or close and reopen the directory, your view of the directory contents should not change. Sorry I don't have the reference handy. I'll find it later if you need it.

Upvotes: 3

Related Questions