// Given a directory name as an argument, print the
// entries of the names in that file to stdout

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>

int main(int argc, char** argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: ./dirdump <path>\n");
    exit(1);
  }

  DIR* dirp = opendir(argv[1]);
  if (dirp == NULL) {
    fprintf(stderr, "Could not open directory\n");
    exit(1);
  }

  struct dirent *entry;

  entry = readdir(dirp);
  while (entry) {
    printf("%s\n", entry->d_name);
    entry = readdir(dirp);
  }

  closedir(dirp);
  return 0;
}