summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fileutil.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/fileutil.c b/fileutil.c
index 86c4cfc..fa1ccac 100644
--- a/fileutil.c
+++ b/fileutil.c
@@ -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 {