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

int main(int argc, char **argv) {
    int fd = open("fixture.txt", O_RDONLY);
    if (fd < 0) {
        perror("open");
        return 1;
    }

    char byte;
    ssize_t count;
    if (argc > 1 && argv[1][0] == 's') {
        count = syscall(SYS_pread64, fd, &byte, (size_t)1, (off_t)1);
    } else {
        count = pread(fd, &byte, 1, 1);
    }
    if (count < 0) {
        perror("pread");
    } else if (count == 1) {
        putchar(byte);
        putchar('\n');
    }
    close(fd);
    return count == 1 ? 0 : 1;
}
