From 7fbe0d2047ce24014731af7238cdedad6afcfb84 Mon Sep 17 00:00:00 2001 From: olemorud Date: Mon, 20 Mar 2023 11:32:51 +0100 Subject: [PATCH] Add Makefile with strict options --- Makefile | 14 ++++++++++++++ exec_tracker.c | 15 +++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d46dee1 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ + +CC = gcc +CFLAGS = -O3 -g -Wall -Wextra -Werror -std=gnu99 -pedantic + +all: bin/exec_tracker + +clean: bin + rm -f 'bin/exec_tracker' + +bin/exec_tracker: exec_tracker.c bin + $(CC) -o $@ $(CFLAGS) $< + +bin: + mkdir bin diff --git a/exec_tracker.c b/exec_tracker.c index e384b47..5692453 100644 --- a/exec_tracker.c +++ b/exec_tracker.c @@ -316,7 +316,7 @@ static void handle_event(int inotify_instance, int *watched, char **filenames, p += sizeof(struct inotify_event) + event->len) { event = (struct inotify_event *)p; - for (int i = 0; i < watched_len; i++) { + for (size_t i = 0; i < watched_len; i++) { if (watched[i] == event->wd) { fprintf(stderr, "%s ", filenames[i]); counter[i] += 1; @@ -326,9 +326,14 @@ static void handle_event(int inotify_instance, int *watched, char **filenames, } } + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-function" /* Prints event mask values in a human-readable format */ static void print_event(uint32_t event) { + UNUSED(print_event); + if (event & IN_ACCESS) { fprintf(stderr, "IN_ACCESS "); } @@ -363,9 +368,11 @@ static void print_event(uint32_t event) fprintf(stderr, "IN_OPEN "); } } +#pragma GCC diagnostic pop + /* Saves number of recorded events for each - executable t 'uses.log' */ + executable to 'uses.log' */ static void save_result(char **filenames, int *counter, size_t arr_len) { FILE *savefile; @@ -381,8 +388,8 @@ static void save_result(char **filenames, int *counter, size_t arr_len) if (counter[i] == 0) continue; - // fprintf(stdout, "%d %s\n", counter[i], filenames[i]); + fprintf(savefile, "%d %s\n", counter[i], filenames[i]); } fclose(savefile); -} \ No newline at end of file +}