Debian Codegraph @

testsuite/systemtap.syscall/getdents.c

raw
1 /* COVERAGE: getdents getdents64 */
2 #include <unistd.h>
3 #include <sys/syscall.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <stdlib.h>
8
9
10 #define BUFSIZE 512L
11 struct linux_dirent64 *dirp64;
12 struct linux_dirent *dirp;
13
14 #ifdef __NR_getdents
15 static inline int __getdents(unsigned int fd, struct linux_dirent *dirp,
16 unsigned int count)
17 {
18 return syscall(__NR_getdents, fd, dirp, count);
19 }
20 #endif
21
22 static inline int __getdents64(unsigned int fd, struct linux_dirent64 *dirp,
23 unsigned int count)
24 {
25 return syscall(__NR_getdents64, fd, dirp, count);
26 }
27
28 int main() {
29 int fd;
30 void *buf;
31
32 fd = open(".", O_RDONLY);
33 buf = malloc(BUFSIZE);
34 dirp64 = buf;
35 dirp = buf;
36
37
38 // --- successful calls ---
39
40 #ifdef __NR_getdents
41 __getdents(fd, dirp, BUFSIZE);
42 //staptest// getdents (NNNN, XXXX, 512) = NNNN
43 #endif
44
45 __getdents64(fd, dirp64, BUFSIZE);
46 //staptest// getdents (NNNN, XXXX, 512) = NNNN
47
48
49 // --- nasty calls (getdents) ---
50
51 #ifdef __NR_getdents
52 __getdents(-1, dirp, BUFSIZE);
53 //staptest// getdents (-1, XXXX, 512) = NNNN
54
55 __getdents(fd, (struct linux_dirent *)(unsigned long)-1L, BUFSIZE);
56 #ifdef __s390__
57 //staptest// getdents (NNNN, 0x[7]?[f]+, 512) = NNNN
58 #else
59 //staptest// getdents (NNNN, 0x[f]+, 512) = NNNN
60 #endif
61
62 __getdents(fd, dirp, (unsigned int)-1);
63 //staptest// getdents (NNNN, XXXX, 4294967295) = NNNN
64 #endif
65
66
67 // --- nasty calls (getdents64) ---
68
69 __getdents64(-1, dirp64, BUFSIZE);
70 //staptest// getdents (-1, XXXX, 512) = NNNN
71
72 __getdents64(fd, (struct linux_dirent64 *)(unsigned long)-1, BUFSIZE);
73 #ifdef __s390__
74 //staptest// getdents (NNNN, 0x[7]?[f]+, 512) = NNNN
75 #else
76 //staptest// getdents (NNNN, 0x[f]+, 512) = NNNN
77 #endif
78
79 __getdents64(fd, dirp64, (unsigned int)-1);
80 //staptest// getdents (NNNN, XXXX, 4294967295) = NNNN
81
82 free(buf);
83 close(fd);
84
85 return 0;
86 }