#include #include #include #include #include int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "No file name given!\n"); return 1; } int fd = open(argv[1], O_RDWR); if (fd == -1) { int color = errno == ENOENT ? 44 : errno == EACCES ? 41 : errno == EISDIR ? 42 : errno == ELOOP ? 46 : errno == ENXIO ? 45 : 0; fprintf(stderr, "Failed to open file: \e[%dm%s\e[0m.\n", color, strerror(errno)); return 1; } printf("File successfully opened."); close(fd); return 0; }