/* Produce the same output as ls -fi */ #include #include #include #include #include int main(int argc, char **argv) { DIR *directory = opendir("."); struct dirent *p; if (directory == NULL) { perror(argv[0]); return EXIT_FAILURE; } while ((p = readdir(directory)) != NULL) { printf("%6lu\t%s\n", p->d_ino, p->d_name); } /* Make sure we broke out of the while loop because of end-of-directory. */ if (errno != ESUCCESS) { /* Use 0 if you have no macro ESUCCESS. */ perror(argv[0]); return EXIT_FAILURE; } if (closedir(directory) != 0) { perror(argv[0]); return EXIT_FAILURE; } return EXIT_SUCCESS; }