Is there a way to send arguments to ftw() to be used in process each file/directory on the path? It's a bit difficult to have the argument concerned as a global variable due to multithreading issues, i.e having the value as global will be visible to all threads and that would be wrong.
A properly designed C callback interface has a void*
argument that you can use to pass arbitrary data from the surrounding code into the callback. [n]ftw
does not have such an argument, so you're kinda up a creek.
If your compiler supports thread-local variables (the __thread
storage specifier) you can use them instead of globals; this will work but is not really that much tidier than globals.
If your C library has the fts
family of functions, use those instead. They are available on most modern Unixes (including Linux, OSX, and recent *BSD) and gnulib has a fallback implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With