/* Sachidananda */
/* Program to illustrate the ftw(3), file tree walk library */

#include <stdio.h>
#include <stdlib.h>
#define __USE_XOPEN_EXTENDED
#include <ftw.h>

int printname(const char *filepath, const struct stat *file_stat, int flag, \
              struct FTW *ftw_obj) {
  printf("%s\n", filepath);
  return 0;
}

int
main(int argc, char **argv)
{
  int (*print)(const char *, const struct stat *, int, struct FTW *) \
    = printname;

  if (argc < 2) {
    fprintf(stderr, "Usage %s dir_path\n", argv[0]);
    exit(1);
  }

  (void)nftw(argv[1], print, 20, FTW_DEPTH);
  return 0;
}
