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

int
main(void)
{
    int fd, nread;
    char buf[11];

    fd = open("log", O_RDONLY);
    if (fd == -1)
        err(EXIT_FAILURE, "open");

    if (lseek(fd, 9, SEEK_SET) == -1)
        err(EXIT_FAILURE, "lseek");

    printf("before=%ld\n", tell(fd));

    if ((nread = pread(fd, buf, 5, 0)) > 0) {
        buf[nread] = '\0';
        printf("%s\n", buf);
    }
    else if (nread == -1)
        err(EXIT_FAILURE, "pread");

    printf("after=%ld\n", tell(fd));

    exit(EXIT_SUCCESS);
}
