diff options
| -rw-r--r-- | fileutil.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -15,7 +15,7 @@ #include <unistd.h> #include <sys/file.h> #include <stdlib.h> -#include <stdio.h> +#include <errno.h> #include <string.h> #include "fileutil.h" @@ -42,9 +42,11 @@ void to_stderr(char *string) { int open_file(char *path, int flags){ // Read the input file int fd; - if ((fd = open(path, flags, NEW_FILE_PERMS)) <= 2){ + if ((fd = open(path, flags, NEW_FILE_PERMS)) < 0){ + int error = errno; to_stderr(path); - to_stderr(" could not be opened.\n"); + to_stderr(" could not be opened: "); + to_stderr(strerror(error)); exit(1); // Exit if an error occurs } return fd; @@ -176,7 +178,7 @@ void execute_subprogram(arguments_t args, char *argv[]) { int main(int argc, char *argv[]) { arguments_t args = parse_arguments(argc, argv); - if (!args.valid) + if (!args.valid) { to_stderr("Invalid arguments provided."); return 1; } else { |
