// OSTEP Chapter 39, page 17, Reading Directories // #include #include #include 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; } /* $ gcc -Wall -o dir dir.c $ ls -ail total 24 67287841 drwxr-xr-x 2 perry perry 61 Nov 9 07:08 . 58720575 drwxr-xr-x 10 perry perry 97 Nov 8 12:07 .. 67287843 -rwxr-xr-x 1 perry perry 8376 Nov 9 07:08 dir 67287846 -rw-r--r-- 1 perry perry 349 Nov 9 07:08 dir.c 67287842 -rw-r--r-- 1 perry perry 148 Nov 8 12:09 getchar.c 58720647 -rw-r--r-- 1 perry perry 156 Nov 8 11:58 read.c $ ./dir 67287841 . 58720575 .. 58720647 read.c 67287842 getchar.c 67287846 dir.c 67287843 dir $ */