buildsys: Tweak pregen wrt headers_dep
[uclibc-ng.git] / test / misc / dirent.c
blob491e3cf75cd779954d4991dd3832aeee3d162fdc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <dirent.h>
8 #define _DTIFY(DT) [DT] #DT
9 const char * const types[] = {
10 _DTIFY(DT_UNKNOWN),
11 _DTIFY(DT_FIFO),
12 _DTIFY(DT_CHR),
13 _DTIFY(DT_DIR),
14 _DTIFY(DT_BLK),
15 _DTIFY(DT_REG),
16 _DTIFY(DT_LNK),
17 _DTIFY(DT_SOCK),
18 _DTIFY(DT_WHT)
21 int main(int argc, char *argv[])
23 DIR *dirh;
24 struct dirent *de;
25 const char *mydir = (argc == 1 ? "/" : argv[1]);
27 if ((dirh = opendir(mydir)) == NULL) {
28 perror("opendir");
29 return 1;
32 printf("readdir() says:\n");
33 while ((de = readdir(dirh)) != NULL)
34 printf("\tdir entry %s: %s\n", types[de->d_type], de->d_name);
36 closedir(dirh);
38 return 0;