I’m currently using dirent.h and ftw.h for directory traversal at my CGI website 100% programmed in C. I am not sure if they are process safe; would various users interfere with each other while on my site ?
Which functions would you recommend for this purpose ?
It is safe for multiple processes to, for example, use
ftw()to walk the same directory tree at the same time.However it is not necessarily safe for one process to be walking the directory tree while another process is updating the same directory tree structure (ie adding, removing or renaming directories). If you have this situation, then you will need to make your CGI processes use an
flock()advisory lock (you could just have a single empty lockfile in the root of the shared directory tree; processes that want to walk the tree have to take a shared lock on that lockfile, and processes that want to alter the tree have to take an exclusive lock on the lockfile).