summaryrefslogtreecommitdiff
path: root/fileutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'fileutil.c')
-rw-r--r--fileutil.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/fileutil.c b/fileutil.c
index 266569f..7ae3f6c 100644
--- a/fileutil.c
+++ b/fileutil.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <sys/file.h>
#include <stdlib.h>
+#include <string.h>
#include "fileutil.h"
#define FILE_BUF_SIZE 1024
@@ -22,14 +23,14 @@
* Prints a given string to stdout. Returns nothing.
*/
void to_stdout(char *string) {
- write(1, string, sizeof(string));
+ write(1, string, strlen(string));
}
/*
* Prints a given string to stderr. Returns nothing.
*/
void to_stderr(char *string) {
- write(2, string, sizeof(string));
+ write(2, string, strlen(string));
}
/*
@@ -42,6 +43,7 @@ void print_file(char *read_path) {
// Read the input file
if ((infile = open(read_path, O_RDONLY)) <= 2){
to_stderr(read_path);
+ to_stderr(" could not be opened for reading.\n");
exit(1); // Exit if an error occurs
}
@@ -54,7 +56,11 @@ void print_file(char *read_path) {
close(infile);
}
-int main(int argc, char const *argv[]) {
- print_file("logfile.txt");
+int main(int argc, char *argv[]) {
+ if (argc >= 2) {
+ print_file(argv[1]);
+ } else {
+ print_file("logfile.txt");
+ }
return 0;
}