Debian Codegraph @

testsuite/systemtap.syscall/readv.c

raw
1 /* COVERAGE: readv */
2 #define _BSD_SOURCE
3 #define _DEFAULT_SOURCE
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <linux/unistd.h>
10 #include <sys/uio.h>
11 #include <string.h>
12 #include <sys/mman.h>
13
14 int main()
15 {
16 int fd;
17 struct iovec rd_iovec[3];
18 char buf[64];
19
20 mlockall(MCL_CURRENT);
21
22 fd = open("foobar1", O_WRONLY|O_CREAT, 0666);
23 //staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar1", O_WRONLY|O_CREAT[[[[.O_LARGEFILE]]]]?, 0666) = NNNN
24 memset(buf, (int)'B', sizeof(buf));
25 write(fd, buf, sizeof(buf));
26 //staptest// write (NNNN, "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"..., 64) = 64
27
28 close(fd);
29 //staptest// close (NNNN) = 0
30
31 fd = open("foobar1", O_RDONLY);
32 //staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar1", O_RDONLY[[[[.O_LARGEFILE]]]]?) = NNNN
33
34 rd_iovec[0].iov_base = buf;
35 rd_iovec[0].iov_len = sizeof(buf);
36 rd_iovec[1].iov_base = NULL;
37 rd_iovec[1].iov_len = 0;
38 rd_iovec[2].iov_base = NULL;
39 rd_iovec[2].iov_len = 0;
40
41 readv(fd, rd_iovec, 0);
42 //staptest// readv (NNNN, XXXX, 0) = 0
43
44 memset(buf, 0x0, sizeof(buf));
45 readv(fd, rd_iovec, 3);
46 //staptest// readv (NNNN, XXXX, 3) = 64
47
48 rd_iovec[0].iov_len = -1;
49 readv(fd, rd_iovec, 1);
50 //staptest// readv (NNNN, XXXX, 1) = -NNNN (EINVAL)
51
52 rd_iovec[0].iov_base = (char *)-1;
53 rd_iovec[0].iov_len = sizeof(buf);
54 readv(fd, rd_iovec, 1);
55 // On 64-bit platforms, we get a EFAULT. On 32-on-64 bits, we
56 // typically get a 0.
57 //staptest// readv (NNNN, XXXX, 1) = [[[[0!!!!-NNNN (EFAULT)]]]]
58
59 rd_iovec[0].iov_base = buf;
60 rd_iovec[0].iov_len = sizeof(buf);
61 readv(-1, rd_iovec, 1);
62 //staptest// readv (-1, XXXX, 1) = -NNNN (EBADF)
63
64 readv(fd, rd_iovec, -1);
65 //staptest// readv (NNNN, XXXX, -1) = -NNNN (EINVAL)
66
67 close (fd);
68 //staptest// close (NNNN) = 0
69
70 mkdir("dir1", S_IREAD|S_IWRITE|S_IEXEC);
71 //staptest// [[[[mkdir (!!!!mkdirat (AT_FDCWD, ]]]]"dir1", 0700) = 0
72
73 fd = open("dir1", O_RDONLY);
74 //staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"dir1", O_RDONLY) = NNNN
75
76 readv(fd, rd_iovec, 1);
77 //staptest// readv (NNNN, XXXX, 1) = -NNNN (EISDIR)
78
79 close (fd);
80 //staptest// close (NNNN) = 0
81
82 return 0;
83 }