title: c programming - directory name from DIR* struct
body: <p>from <a href="https://github.com/tronkko/dirent/blob/master/include/dirent.h" rel="nofollow noreferrer">dirent.h</a> we can see that DIR struct is  </p>
  
  <pre><code>struct DIR {
      struct dirent ent;
      struct _WDIR *wdirp;
  };
  </code></pre>
  
  <p>and <strong>dirent</strong> struct is  </p>
  
  <pre><code>struct dirent {
      /* Always zero */
      long d_ino;
  
      /* File position within stream */
      long d_off;
  
      /* Structure size */
      unsigned short d_reclen;
  
      /* Length of name without \0 */
      size_t d_namlen;
  
      /* File type */
      int d_type;
  
      /* File name */
      char d_name[PATH_MAX+1];
  };
  </code></pre>
  
  <p>My question is: If we have only DIR * struct -let say <strong>dir</strong> -and from this struct we want to extract directory name, normally we -should? - do:</p>
  
  <pre><code>const char * dirname = dir-&gt;ent.d_name;
  </code></pre>
  
  <p>however this not compile, error is:  </p>
  
  <pre><code>dereferencing pointer to incomplete type
  </code></pre>
  
  <p>Thanks </p>