11 #define CHUNK K_1 /* single chunk */
13 #define DATA_FILE "writev_data_file"
15 static char buf1
[K_1
];
16 static char buf2
[K_1
];
17 static char *buf_list
[NBUFS
], f_name
[]="writev_data_file";
20 struct iovec wr_iovec
[MAX_IOVEC
] = {
29 /* Fill the buf_list[0] and buf_list[1] with 0 zeros */
32 memset(buf_list
[0], 0, K_1
);
33 memset(buf_list
[1], 0, K_1
);
35 if ((fd
= open(f_name
, O_WRONLY
| O_CREAT
, 0666)) < 0) {
36 fprintf(stderr
, "open(2) failed: fname = %s, errno = %d\n",
39 } else if ((nbytes
= write(fd
, buf_list
[1], K_1
)) != K_1
) {
40 fprintf(stderr
, "write(2) failed: nbytes = %d, errno = %d\n",
45 fprintf(stderr
, "close failed: errno = %d\n", errno
);
48 fprintf(stderr
, "Test file created.\n");
49 if ((fd
= open(f_name
, O_RDWR
, 0666)) < 0) {
50 fprintf(stderr
, "open failed: fname = %s, errno = %d\n",
56 if (writev(fd
, wr_iovec
, 2) < 0) {
58 fprintf(stderr
, "Received EFAULT as expected\n");
60 fprintf(stderr
, "Expected EFAULT, got %d\n", errno
);
62 if ((nbytes
= read(fd
, buf_list
[0], CHUNK
)) != 0)
63 fprintf(stderr
, "Expected nbytes = 0, got %d\n", nbytes
);
66 fprintf(stderr
, "Error writev returned a positive value\n");
67 // Now check invalid vector count
68 if (writev(fd
, wr_iovec
, -1) < 0) {
70 fprintf(stderr
, "Received EINVAL as expected\n");
72 fprintf(stderr
, "expected errno = EINVAL, got %d\n", errno
);
75 fprintf(stderr
, "Error writev returned a positive value\n");
76 if (readv(fd
, wr_iovec
, -1) < 0) {
78 fprintf(stderr
, "Received EINVAL as expected\n");
80 fprintf(stderr
, "expected errno = EINVAL, got %d\n", errno
);
83 fprintf(stderr
, "Error readv returned a positive value\n");
85 // test with totally bogus iovec pointer
87 if (writev(fd
, (const struct iovec
*)1, 1) < 0) {
89 fprintf(stderr
, "Received EFAULT as expected\n");
91 fprintf(stderr
, "Expected EFAULT, got %d\n", errno
);
94 fprintf(stderr
, "Error writev returned a positive value\n");
96 if (readv(fd
, (const struct iovec
*)1, 1) < 0) {
98 fprintf(stderr
, "Received EFAULT as expected\n");
100 fprintf(stderr
, "Expected EFAULT, got %d\n", errno
);
103 fprintf(stderr
, "Error readv returned a positive value\n");