diff options
| author | Thorsten Töpper <atsutane@freethoughts.de> | 2025-06-16 20:20:20 +0200 |
|---|---|---|
| committer | Thorsten Töpper <atsutane@freethoughts.de> | 2025-06-16 20:20:20 +0200 |
| commit | be8f8a9f4caa883e3de98b276cdad55d4fc65c0d (patch) | |
| tree | 40148ab39566cfa614ca9a5e64049ff54cdd1e84 /src | |
| parent | 62e45906f1ffcaa2e3039a4306c01465c3eadfd8 (diff) | |
| download | dir_monitor-be8f8a9f4caa883e3de98b276cdad55d4fc65c0d.tar.gz dir_monitor-be8f8a9f4caa883e3de98b276cdad55d4fc65c0d.tar.bz2 | |
CMakeLists: hardening flags
Diffstat (limited to 'src')
| -rw-r--r-- | src/dir_monitor.c | 4 | ||||
| -rw-r--r-- | src/list_management.c | 6 | ||||
| -rw-r--r-- | src/options.c | 6 | ||||
| -rw-r--r-- | src/output.c | 6 |
4 files changed, 11 insertions, 11 deletions
diff --git a/src/dir_monitor.c b/src/dir_monitor.c index b2257ce..df85f18 100644 --- a/src/dir_monitor.c +++ b/src/dir_monitor.c @@ -110,7 +110,7 @@ struct list_head *get_data_from_directory(char *path) { int main(int argc, char **argv) { struct list_head *list = NULL; int path_index = 1; - /* TODO: Handle options */ + if (argc < 2) { usage(argv[0]); return EXIT_FAILURE; @@ -120,9 +120,11 @@ int main(int argc, char **argv) { usage(argv[0]); return EXIT_FAILURE; } + list = get_data_from_directory(argv[path_index]); print_list(list); destroy_list(list); + return EXIT_SUCCESS; } diff --git a/src/list_management.c b/src/list_management.c index 634b884..3b02d7f 100644 --- a/src/list_management.c +++ b/src/list_management.c @@ -15,9 +15,10 @@ /* === IMPLEMENTATION === */ -inline struct list_node *create_node(char *fname, size_t fsize, time_t ftime) { + +inline struct list_node *create_node(char *fname, off_t fsize, time_t ftime) { struct list_node *node = NULL; - + if (fname == NULL || fname[0] == '\0') { LOGERR("ERROR: No valid filename given\n"); return NULL; @@ -97,7 +98,6 @@ inline int insert_sorted_by_time(struct list_head *list, struct list_node *node) INSERT_BY_NUMERIC_FIELD(list, node, ftime); return -3; } -#undef INSERT_BY_NUMERIC_FIELD struct list_head *create_list_sort_reversed(struct list_head *list) { diff --git a/src/options.c b/src/options.c index 848eaf5..2136c83 100644 --- a/src/options.c +++ b/src/options.c @@ -2,8 +2,6 @@ /* Copyright 2025 Thorsten Töpper * - * options - - * * vim:ts=4:sw=4:expandtab */ #include <stdio.h> @@ -11,14 +9,11 @@ #include <getopt.h> #include <stdbool.h> - #include "output.h" #include "options.h" - - /* === GLOBAL VARIABLES === */ struct option long_options[] = { { "reverse-sort", no_argument, 0, 0 }, @@ -97,6 +92,7 @@ void set_option(const char *option_name, char *option_argument) { LOGERR("ERROR: Option '%s' not recognized\n.", option_name); } + int parse_arguments(int argc, char **argv) { int c = 0, index; diff --git a/src/output.c b/src/output.c index 9dd274b..be0afb1 100644 --- a/src/output.c +++ b/src/output.c @@ -63,7 +63,7 @@ void print_list(struct list_head *list) { ptr = lh->first; while (ptr != NULL) { - printf(" %8lu %2s ", ((ptr->fsize>=1024) ? (ptr->fsize/1024) : ptr->fsize), + printf(" %8ld %2s ", ((ptr->fsize>=1024) ? (ptr->fsize/1024) : ptr->fsize), ((ptr->fsize >= 1024) ? "kB" : "")); tm = localtime(&ptr->ftime); @@ -75,7 +75,9 @@ void print_list(struct list_head *list) { printf(" %8s ", timestamp); } printf(" %s\n", ptr->fname); - total_size += ptr->fsize; + /* Linux: Neither man stat(2) nor stat(3type) declare when struct stat field st_size + * get's a negative value. */ + total_size += (ptr->fsize>0) ? (unsigned long int)ptr->fsize : 0; ptr = ptr->next; } fputc_all_cols('=', stdout); |
