I'm currently working on code that is very sensitive to I / O in terms of performance, and I'm looking for the fastest way to remove a Unix directory from C code. I want to write something that works on all common platforms (Android, MacOS X, Linux), but I am ready to write different implementations for different tastes of Unix (I suspect that BSD / MacOS X and Linux / Android have great tricks).
Here are a few things that crossed my mind:
on all platforms, I can navigate the directory structure with opendir, readdir_ret al., using dirent->_d_typeto distinguish directories from files - this seems standardized on Linux, but not MacOS X;
under Linux / Android, if I choose this option, I can also use dirfdand unlinkatto quickly remove each file;
on all platforms, I can navigate through the directory structure with ftw, using flagto distinguish between directories from files;
on all platforms, I can navigate through the directory structure using fts_open, fts_readetc., using FTSENT->fts_infoto distinguish directories from files;
I did not check, but I get the impression that the BSD / MacOS X function copyfilecan be used to delete a directory.
Is one of these methods better than the other? Am I missing something?
Please note that I am mainly interested in minimizing I / O and, in a more general sense, system calls - I'm not too greedy due to processor costs.
thank