Initial import of a bitmap implementation as part of a filesystem project
[eleutheria.git] / fileops / listdir.c
blob61954598312cae055dae494a8cb5fbb302ff36ff
1 /* compile with:
2 gcc listdir.c -o listdir -Wall -W -Wextra -ansi -pedantic */
4 #include <dirent.h>
5 #include <stdio.h>
6 #include <stdlib.h>
8 int main(int argc, char *argv[])
10 struct dirent *pdent;
11 DIR *pdir;
13 /* Check argument count */
14 if (argc != 2) {
15 fprintf(stderr, "Usage: %s directory\n", argv[0]);
16 exit(EXIT_FAILURE);
19 /* Open directory named by argv[1], associate a directory stream
20 * with it and return a pointer to it
22 if ((pdir = opendir(argv[1])) == NULL) {
23 perror("opendir");
24 exit(EXIT_FAILURE);
27 /* Get all directory entries */
28 while((pdent = readdir(pdir)) != NULL)
29 printf("%s\n", pdent->d_name);
31 closedir(pdir);
32 return EXIT_SUCCESS;