#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <err.h>
#include "../lpi.h"

int
main(int argc, char *argv[])
{
    int fd, newfd;

    fd = open("log", O_RDWR | O_APPEND | O_NONBLOCK | O_DSYNC | O_ASYNC | O_SYNC);
    if (fd == -1)
        err(EXIT_FAILURE, "open");

    if ((newfd = ddup(fd)) == -1)
        err(EXIT_FAILURE, "ddup");

    lseek(fd, 150, SEEK_SET);

    int fdFlags = fcntl(fd, F_GETFL);
    int newfdFlags = fcntl(newfd, F_GETFL);

    printf("tell(newfd)=%lld\n", (long long) tell(newfd));

    printf("   fd flags: %s\n", toBase(fdFlags, 16, 4, 2, ' '));
    printf("newfd flags: %s\n", toBase(newfdFlags, 16, 4, 2, ' '));


    exit(EXIT_FAILURE);
}
