#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/uio.h>
#include <unistd.h>

int main(void) {
    char byte;
    struct iovec iov = { .iov_base = &byte, .iov_len = 1 };
    errno = 0;
    int advice = posix_fadvise(-1, 0, 1, POSIX_FADV_WILLNEED);
    int advice_errno = errno;
    errno = 0;
    ssize_t ahead = readahead(-1, 0, 1);
    int ahead_errno = errno;
    errno = 0;
    ssize_t read_result = preadv2(-1, &iov, 1, 0, RWF_NOWAIT);
    int read_errno = errno;

    printf("{\"EBADF\":%d,\"observations\":["
           "{\"api\":\"posix_fadvise\",\"return\":%d,\"errno\":%d},"
           "{\"api\":\"readahead\",\"return\":%zd,\"errno\":%d},"
           "{\"api\":\"preadv2\",\"return\":%zd,\"errno\":%d}]}\n",
           EBADF, advice, advice_errno, ahead, ahead_errno,
           read_result, read_errno);
    /* Only the documented error channel is asserted for each interface. */
    return !(advice == EBADF && ahead == -1 && ahead_errno == EBADF
             && read_result == -1 && read_errno == EBADF);
}
