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
37
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#define __USE_FILE_OFFSET64

int
main (int argc, char *argv[])
{
        DIR *d;
        struct dirent *ent = NULL;
        char buf[sizeof(*ent)+256];

        if (argc != 2) {
                fprintf (stderr, "Usage: %s <dirname>\n", argv[0]);
                return 1;
        }

        d = opendir (argv[1]);
        if (!d) {
                fprintf (stderr, "%s: %s\n", argv[1], strerror (errno));
                return 1;
        }

        for (;;) {
                ent = NULL;
                readdir_r (d, (void *)buf, &ent);
                if (!ent)
                        break;
                printf ("%s: %llu (%llu)\n", ent->d_name, ent->d_off, telldir (d));
        }                                                                                                                                                                   
                                                                                                                                                                            
        return 0;                                                                                                                                                           
}