#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/uio.h>

int main()
{
    int fd, n;
    char buf1[6];
    char buf2[6];
    struct iovec iov[2];

    fd = open("readv.t", O_RDONLY);
    if (fd == -1) {
        perror("open");
        return 1;
    }

    buf1[6] = 0;
    buf2[6] = 0;

    iov[0].iov_base = buf1;
    iov[0].iov_len  = 5;

    iov[1].iov_base = buf2;
    iov[1].iov_len  = 5;

    n = readv(fd, iov, 2);

    if (n == -1) {
        perror("readv");
        close(fd);
        return 1;
    }

    printf("readv read %zd bytes\n", n);
    printf("buf1 = \"%s\"\n", buf1);
    printf("buf2 = \"%s\"\n", buf2);

    close(fd);
    return 0;
}
