title: How to walk a directory in C
body: <p>I am using glib in my application, and I see there are convenience wrappers in glib for C's <code>remove</code>, <code>unlink</code> and <code>rmdir</code>. But these only work on a single file or directory at a time.</p>
  
  <p>As far as I can see, neither the C standard nor glib include any sort of recursive directory walk functionality. Nor do I see any specific way to delete an entire directory tree at once, as with <code>rm -rf</code>.</p>
  
  <p>For what I'm doing this I'm not worried about any complications like permissions, symlinks back up the tree (infinite recursion), or anything that would rule out a very naive
  implementation... so I am not averse to writing my own function for it.</p>
  
  <p>However, I'm curious if this functionality is out there somewhere in the standard libraries gtk or glib (or in some other easily reused C library) already and I just haven't stumbled on it. Googling this topic generates a lot of false leads.</p>
  
  <p>Otherwise my plan is to use this type of algorithm:</p>
  
  <pre><code>dir_walk(char* path, void* callback(char*) {
    if(is_dir(path) &amp;&amp; has_entries(path)) {
      entries = get_entries(path);
      for(entry in intries) { dir_walk(entry, callback); }
    }
    else { callback(path) }
  }
  
  dir_walk("/home/user/trash", remove);
  </code></pre>
  
  <p>Obviously I would build in some error handling and the like to abort the process as soon as a fatal error is encountered.</p>