Fix to not run gdbserver.
[nethome.git] / src / getdents64.c
1 /* $Id$ */
2
3 #define _GNU_SOURCE 1
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <dirent.h>
11 #include <unistd.h>
12 #include <assert.h>
13 #include <linux/unistd.h>
14 #include <string.h>
15
16
17 static _syscall3(long, getdents64, uint, fd, struct dirent64 *, dirp, uint, count);
18
19 int main(int argc,char **argv)
20 {
21 int fd;
22
23         if (argc!=2) {
24                 fprintf(stderr,"Required directory name argument!\n");
25                 exit(EXIT_FAILURE);
26                 }
27         if (-1==(fd=open(argv[1],O_RDONLY /* |O_DIRECTORY */))) {
28                 fprintf(stderr,"open(\"%s\"): %m\n",argv[1]);
29                 exit(EXIT_FAILURE);
30                 }
31         for (;;) {
32 off_t off;
33 char buf[100];
34 struct dirent64 *dirent64;
35 int got;
36
37                 if ((off_t)-1==(off=lseek(fd,0,SEEK_CUR))) {
38                         fprintf(stderr,"lseek(): %m\n");
39                         exit(EXIT_FAILURE);
40                 }
41                 printf("@=%lld\n",(long long)off);
42                 memset(buf,0,sizeof(buf));
43                 got=getdents64(fd,(void *)buf,sizeof(buf));
44                 printf("got=%d\n",got);
45                 if (got==-1)
46                         perror("getdents()");
47                 assert(got<=sizeof(buf));
48                 if (!got)
49                         break;
50                 for (
51                                 dirent64=(void *)buf;
52                                 (char *)dirent64<buf+got;
53                                 dirent64=(void *)((char *)dirent64+dirent64->d_reclen)
54                                 ) {
55                         printf("dirent64_rel=%d, d_off=0x%llx; d_ino=%llu, d_reclen=%u, d_type=%u, d_name=%s\n",
56                                         (char *)dirent64-buf,
57                                         (long long)dirent64->d_off,(unsigned long long)dirent64->d_ino,
58                                         (unsigned)dirent64->d_reclen,
59                                         (unsigned)dirent64->d_type,dirent64->d_name);
60                         }
61                 printf("trailing=%d\n",(buf+got)-(char *)dirent64);
62                 }
63         puts("done");
64         return EXIT_SUCCESS;
65 }