--- /dev/null
+/* $Id$ */
+
+#define _GNU_SOURCE 1
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <assert.h>
+#include <linux/unistd.h>
+#include <string.h>
+
+
+static _syscall3(long, getdents64, uint, fd, struct dirent64 *, dirp, uint, count);
+
+int main(int argc,char **argv)
+{
+int fd;
+
+ if (argc!=2) {
+ fprintf(stderr,"Required directory name argument!\n");
+ exit(EXIT_FAILURE);
+ }
+ if (-1==(fd=open(argv[1],O_RDONLY /* |O_DIRECTORY */))) {
+ fprintf(stderr,"open(\"%s\"): %m\n",argv[1]);
+ exit(EXIT_FAILURE);
+ }
+ for (;;) {
+off_t off;
+char buf[100];
+struct dirent64 *dirent64;
+int got;
+
+ if ((off_t)-1==(off=lseek(fd,0,SEEK_CUR))) {
+ fprintf(stderr,"lseek(): %m\n");
+ exit(EXIT_FAILURE);
+ }
+ printf("@=%lld\n",(long long)off);
+ memset(buf,0,sizeof(buf));
+ got=getdents64(fd,(void *)buf,sizeof(buf));
+ printf("got=%d\n",got);
+ if (got==-1)
+ perror("getdents()");
+ assert(got<=sizeof(buf));
+ if (!got)
+ break;
+ for (
+ dirent64=(void *)buf;
+ (char *)dirent64<buf+got;
+ dirent64=(void *)((char *)dirent64+dirent64->d_reclen)
+ ) {
+ printf("dirent64_rel=%d, d_off=0x%llx; d_ino=%llu, d_reclen=%u, d_type=%u, d_name=%s\n",
+ (char *)dirent64-buf,
+ (long long)dirent64->d_off,(unsigned long long)dirent64->d_ino,
+ (unsigned)dirent64->d_reclen,
+ (unsigned)dirent64->d_type,dirent64->d_name);
+ }
+ printf("trailing=%d\n",(buf+got)-(char *)dirent64);
+ }
+ puts("done");
+ return EXIT_SUCCESS;
+}