The function opendir() returns a pointer to a directory stream DIR *, which apparently is an opaque data type. The implementation is hidden.
The libc manual states that you should not allocate a DIR object yourself and let the directory functions handle the allocation.
Is there any way to manipulate a directory stream after obtaining it with opendir() and before passing it to, for example, readdir()?
I basically want to overload opendir() with LD_PRELOAD to return a manipulated directory stream, which is used by readdir().
It might help to look at what the
LD_PRELOADsortdirdoes as it sorts the directory entries before giving them to the program although what you might want to do might be something other than sorting.sortdirreplacesopendir,readdir,readdir64, andclosedirand being only 197 lines of code, it would serve you well to look at it.