#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

int main(void) {
    int fd;

    fd = open("no_such_file.txt", O_RDONLY);

    if (fd == -1) {
        printf("open() failed\n");

        printf("errno value: %d\n", errno);

        if (errno == ENOENT) {
            printf("Reason: file does not exist\n");
        } else if (errno == EACCES) {
            printf("Reason: permission denied\n");
        }

        printf("strerror(errno): %s\n", strerror(errno));

        perror("perror says");
        return 1;
    }

    printf("File opened successfully\n");
    close(fd);

    return 0;
}
