| 1 |
/* COVERAGE: sendfile sendfile64 */ |
| 2 |
#include <fcntl.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <stdio.h> |
| 5 |
#include <sys/sendfile.h> |
| 6 |
#include <sys/stat.h> |
| 7 |
#include <sys/types.h> |
| 8 |
#include <unistd.h> |
| 9 |
#include <string.h> |
| 10 |
#include <limits.h> |
| 11 |
|
| 12 |
int main () |
| 13 |
{ |
| 14 |
int fd, read_fd; |
| 15 |
int write_fd; |
| 16 |
off_t offset = 0; |
| 17 |
char buff[22]; // Note below 22 == EINVAL |
| 18 |
int ret; |
| 19 |
|
| 20 |
memset(buff, 5, sizeof(buff)); |
| 21 |
|
| 22 |
/* create a file with something in it */ |
| 23 |
fd = creat("foobar",S_IREAD|S_IWRITE); |
| 24 |
write(fd, buff, sizeof(buff)); |
| 25 |
fsync(fd); |
| 26 |
close(fd); |
| 27 |
read_fd = open ("foobar", O_RDONLY); |
| 28 |
if (read_fd < 0) |
| 29 |
return 1; |
| 30 |
|
| 31 |
/* Open the output file for writing */ |
| 32 |
write_fd = creat("foobar2",S_IREAD|S_IWRITE|S_IRWXO); |
| 33 |
|
| 34 |
/* |
| 35 |
* For 2.6 the write_fd had to be a socket otherwise |
| 36 |
* sendfile would fail. So we also test for failure here. |
| 37 |
*/ |
| 38 |
ret = sendfile (write_fd, read_fd, &offset, sizeof(buff)); |
| 39 |
//staptest// sendfile (NNNN, NNNN, XXXX, 22) = -?22 |
| 40 |
|
| 41 |
sendfile (-1, read_fd, &offset, sizeof(buff)); |
| 42 |
//staptest// sendfile (-1, NNNN, XXXX, 22) = -NNNN (EBADF) |
| 43 |
|
| 44 |
sendfile (write_fd, -1, &offset, sizeof(buff)); |
| 45 |
//staptest// sendfile (NNNN, -1, XXXX, 22) = -NNNN (EBADF) |
| 46 |
|
| 47 |
sendfile (write_fd, read_fd, (off_t *)-1, sizeof(buff)); |
| 48 |
#ifdef __s390__ |
| 49 |
//staptest// sendfile (NNNN, NNNN, 0x[7]?[f]+, 22) = -NNNN (EFAULT) |
| 50 |
#else |
| 51 |
//staptest// sendfile (NNNN, NNNN, 0x[f]+, 22) = -NNNN (EFAULT) |
| 52 |
#endif |
| 53 |
|
| 54 |
sendfile (write_fd, read_fd, &offset, -1); |
| 55 |
// The 'count' argument is a size_t, which is an unsigned |
| 56 |
// long, whose size varies by platform. (The return value |
| 57 |
// varies here as well, so we'll just ignore it.) |
| 58 |
#if __WORDSIZE == 64 |
| 59 |
//staptest// sendfile (NNNN, NNNN, XXXX, 18446744073709551615) |
| 60 |
#else |
| 61 |
//staptest// sendfile (NNNN, NNNN, XXXX, 4294967295) |
| 62 |
#endif |
| 63 |
close (read_fd); |
| 64 |
close (write_fd); |
| 65 |
unlink("foobar"); |
| 66 |
unlink("foobar2"); |
| 67 |
|
| 68 |
return 0; |
| 69 |
} |