#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <err.h>
#include "../lpi.h"         // for tell()

int
main(int argc, char *argv[])
{
    pid_t pid;
    off_t off;
    int fd;

    if ((fd = open("fork_1.c", O_RDONLY)) == -1)
        err(EXIT_FAILURE, "open");

    if ((pid = fork()) == -1)
        err(EXIT_FAILURE, "fork");

    if (pid == 0) {
        if (lseek(fd, -5, SEEK_END) == -1)
            err(EXIT_FAILURE, "child - lseek");
        printf(" child file offset=%ld\n", tell(fd));
        exit(EXIT_SUCCESS); // _exit()?
    }

    sleep(3);               // Give chance to child to run first.
    printf("parent file offset=%ld\n", lseek(fd, 0, SEEK_CUR));
    exit(EXIT_SUCCESS);
}
