1 /* Tests sendfilev with bogus inputs. */
9 #include <sys/sendfile.h>
11 #define CHUNK (8 * 1024)
12 #define TEST_FILE "sendfile.test"
14 int main(int argc
, const char *argv
[])
16 int test_fd
= open(TEST_FILE
, O_WRONLY
| O_CREAT
, 0666);
19 fprintf(stderr
, "open failed: %s (%d).\n", strerror(error
), error
);
24 bzero(&chunk1
, sizeof(chunk1
));
25 ssize_t nbytes
= write(test_fd
, &chunk1
, sizeof(chunk1
));
26 if (nbytes
!= CHUNK
) {
28 fprintf(stderr
, "write failed (nbytes=%zd): %s (%d).\n",
29 nbytes
, strerror(error
), error
);
34 printf("Test file created.\n");
36 test_fd
= open(TEST_FILE
, O_RDWR
, 0666);
39 fprintf(stderr
, "open failed: %s (%d).\n", strerror(error
), error
);
44 vec
[0].sfv_fd
= SFV_FD_SELF
;
48 vec
[1].sfv_fd
= test_fd
;
50 vec
[1].sfv_len
= CHUNK
;
54 nbytes
= sendfilev(test_fd
, vec
, 2, &xferred
);
56 if (errno
== EFAULT
) {
57 printf("Received EFAULT as expected.\n");
59 fprintf(stderr
, "Expected EFAULT, got %d.\n", errno
);
62 fprintf(stderr
, "Error: sendfilev returned a positive value.\n");
65 nbytes
= sendfilev(test_fd
, vec
, -1, &xferred
);
67 if (errno
== EINVAL
) {
68 printf("Received EINVAL as expected.\n");
70 fprintf(stderr
, "Expected EINVAL, got %d.\n", errno
);
73 fprintf(stderr
, "Error: sendfilev returned a positive value.\n");
76 vec
[0].sfv_off
= (off_t
) "HEADER";
78 nbytes
= sendfilev(test_fd
, vec
, 1, &xferred
);
81 fprintf(stderr
, "sendfilev failed: %s (%d).\n", strerror(error
), error
);
83 printf("sendfilev for the first buffer succeeded.\n");