title: Can I manipulate a directory stream obtained with opendir()?
body: <p>The function <code>opendir()</code> returns a pointer to a directory stream <code>DIR *</code>, which apparently is an opaque data type. The implementation is hidden.</p>
  
  <p>The <a href="http://www.gnu.org/software/libc/manual/html_node/Opening-a-Directory.html" rel="nofollow">libc manual</a> states that you should not allocate a <code>DIR</code> object yourself and let the directory functions handle the allocation.</p>
  
  <p>Is there any way to manipulate a directory stream after obtaining it with <code>opendir()</code> and before passing it to, for example, <code>readdir()</code>?</p>
  
  <p>I basically want to overload  <code>opendir()</code> with <code>LD_PRELOAD</code> to return a manipulated directory stream, which is used by <code>readdir()</code>.</p>