#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <err.h>
#include <unistd.h>

int
main(void)
{
    int fd;
    unsigned int flags;
    char buf[10] = "sal";

    fd = open("tfile", O_WRONLY);
    if (fd == -1)
        err(EXIT_FAILURE, "open");
    if (write(fd, buf, 3) == -1)
        err(EXIT_FAILURE, "read");

    if ((flags = fcntl(fd, F_GETFL)) == -1)
        err(EXIT_FAILURE, "fcntl");

    printf("%x\n", flags);

    flags |= O_APPEND | O_DIRECT | O_NONBLOCK | O_ASYNC;

    if (fcntl(fd, F_SETFL, flags) == -1)
        err(EXIT_FAILURE, "fcntl");

    if ((flags = fcntl(fd, F_GETFL)) == -1)
        err(EXIT_FAILURE, "F_GETFL");

    printf("%x\n", flags);
    if (flags & O_ASYNC)
        printf("ok!\n");

    exit(EXIT_SUCCESS);
}
