aboutsummaryrefslogtreecommitdiffstats
path: root/tests/readdir_inode.c
blob: a216c7edcc37af956b4699bdb7ea9ab64f7552db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>

int main(int argc, char* argv[])
{
    DIR* dirp;
    struct dirent* dent;
    
    if (argc != 2) {
        fprintf(stderr, "Usage: readdir_inode dir\n");
        return 1;
    }
    
    dirp = opendir(argv[1]);
    if (dirp == NULL) {
        perror("failed to open directory");
        return 2;
    }
    
    dent = readdir(dirp);
    while (dent != NULL) {
        if (errno != 0) {
            perror("failed to read directory entry");
            return 3;
        }
        printf("%llu %s\n", (unsigned long long)dent->d_ino, dent->d_name);
        dent = readdir(dirp);
    }
    
    closedir(dirp);
    
    return 0;
}