This answer recommends fts
as a good way to have a reentrant filesystem traversal. While reading the manpages, however, I noticed that fts_read
and fts_children
are marked as MT-Unsafe
.
I could not find anywhere information on why it was marked as such. I found this thread, so I suspect the reason is because of chdir
being called (two threads will try to chdir
the process at the same time, it can't be good).
If that is so, I guess that passing FTS_NOCHDIR
would be enough to have thread safety. Is there any other reason I don't see?
(And for the record, I'm very surprised that we came to this day without having a good reentrant, reasonable to use way of scanning through a filesystem tree! Seriously? ☺)