6. Reading Directories

The only standard fields in a directory entry structure are d_ino and d_name:
struct dirent
{
  ino_t  d_ino;       // Inode number
  char   d_name[256]; // Null-terminated filename
  //...
};
Example program from chapter 39 page 16:
#include <stdio.h>
#include <dirent.h>
#include <assert.h>

int main(int argc, char *argv[]) {
  DIR *dp = opendir(".");
  assert(dp != NULL);
  struct dirent *d;
  while ((d = readdir(dp)) != NULL) {
    printf("%lu %s\n", (unsigned long) d->d_ino, d->d_name);
  }
  closedir(dp);
  return 0;
}