diff options
| author | Thorsten Töpper <atsutane@freethoughts.de> | 2025-06-12 21:28:03 +0200 |
|---|---|---|
| committer | Thorsten Töpper <atsutane@freethoughts.de> | 2025-06-12 21:28:03 +0200 |
| commit | 45fc2872aee9af15a61d8dbae8bd9d2c8eecb437 (patch) | |
| tree | 7e53de6f39e5a78da81da08daac8200c62f9a9e2 /dir_monitor.c | |
| parent | 4cf97bf17aaa2bdec383b727314d410544774dd1 (diff) | |
| download | dir_monitor-45fc2872aee9af15a61d8dbae8bd9d2c8eecb437.tar.gz dir_monitor-45fc2872aee9af15a61d8dbae8bd9d2c8eecb437.tar.bz2 | |
dir_monitor: timestamp in simple output
Diffstat (limited to 'dir_monitor.c')
| -rw-r--r-- | dir_monitor.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/dir_monitor.c b/dir_monitor.c index 42d90dc..9903b12 100644 --- a/dir_monitor.c +++ b/dir_monitor.c @@ -51,8 +51,8 @@ void print_list(struct list_head *list); /* === GLOBAL VARIABLES === */ -bool show_hidden_entries = false; - +bool option_show_hidden_entries = false; +bool option_timestamp_short = true; /* === IMPLEMENTATION === */ @@ -134,6 +134,7 @@ inline int insert_sorted_by_size(struct list_head *list, struct list_node *node) void print_list(struct list_head *list) { struct list_node *ptr; struct tm *tm = NULL; + char timestamp[128]; if (list == NULL) return; @@ -141,7 +142,16 @@ void print_list(struct list_head *list) { while (ptr != NULL) { printf(" %8lu %2s ", ((ptr->fsize>=1024) ? (ptr->fsize/1024) : ptr->fsize), ((ptr->fsize >= 1024) ? "kB" : "")); - /* TODO: time here */ + + tm = localtime(&ptr->ftime); + if (option_timestamp_short) { + strftime(timestamp, sizeof(timestamp), "%H:%M:%S", tm); + printf(" %8s ", timestamp); + } else { + strftime(timestamp, sizeof(timestamp), "%Y%m%d %H:%M:%S %Z", tm); + printf(" %20s ", timestamp); + } + printf(" %s\n", ptr->fname); ptr = ptr->next; } @@ -188,7 +198,7 @@ struct list_head *get_data_from_directory(char *path) { errno = 0; /* Show hidden entries code is UNIXoid specific, needs to be adjusted for portability */ while ((de = readdir(dir)) != NULL) { - if (de->d_name[0] == '.' && show_hidden_entries == false) + if (de->d_name[0] == '.' && option_show_hidden_entries == false) continue; sprintf(fname_in_path, "%s", de->d_name); |
