aboutsummaryrefslogtreecommitdiff
path: root/src/output.c
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2025-06-20 01:45:13 +0200
committerThorsten Töpper <atsutane@freethoughts.de>2025-06-20 01:45:13 +0200
commit49997ac30b46c42a0366423cb2048f8257774805 (patch)
tree6ff70c9eecf1276a64360840d697516400e3dcb1 /src/output.c
parent522ff099416b66868ef5782b6548d28917369b47 (diff)
downloaddir_monitor-49997ac30b46c42a0366423cb2048f8257774805.tar.gz
dir_monitor-49997ac30b46c42a0366423cb2048f8257774805.tar.bz2
Store everything from lstat()
Diffstat (limited to 'src/output.c')
-rw-r--r--src/output.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/output.c b/src/output.c
index be0afb1..64971fa 100644
--- a/src/output.c
+++ b/src/output.c
@@ -11,6 +11,7 @@
#include <sys/ioctl.h>
#include "output.h"
+#include "list_management.h"
#include "options.h"
@@ -49,6 +50,7 @@ void print_list(struct list_head *list) {
struct list_head *lh = list;
struct list_node *ptr;
struct tm *tm = NULL;
+ time_t time_value = 0;
char timestamp[128];
size_t total_size = 0;
@@ -63,10 +65,30 @@ void print_list(struct list_head *list) {
ptr = lh->first;
while (ptr != NULL) {
- printf(" %8ld %2s ", ((ptr->fsize>=1024) ? (ptr->fsize/1024) : ptr->fsize),
- ((ptr->fsize >= 1024) ? "kB" : ""));
+ time_value = 0;
- tm = localtime(&ptr->ftime);
+ switch (option_time_field) {
+ case 'm':
+ time_value = ptr->ln_stat.st_mtim.tv_sec;
+ break;
+ case 'a':
+ time_value = ptr->ln_stat.st_atim.tv_sec;
+ break;
+ case 'c':
+ time_value = ptr->ln_stat.st_ctim.tv_sec;
+ break;
+ default:
+ LOGERR("WARNING: option_time_field has invalid value %c 0x%02X - going by default m\n",
+ option_time_field, option_time_field);
+ option_time_field = 'm';
+ time_value = ptr->ln_stat.st_mtim.tv_sec;
+ break;
+ };
+
+ printf(" %8ld %2s ", ((ptr->ln_stat.st_size>=1024) ? (ptr->ln_stat.st_size/1024) : ptr->ln_stat.st_size),
+ ((ptr->ln_stat.st_size >= 1024) ? "kB" : ""));
+
+ tm = localtime(&time_value);
if (option_timestamp_long) {
strftime(timestamp, sizeof(timestamp), "%Y%m%d %H:%M:%S %Z", tm);
printf(" %20s ", timestamp);
@@ -75,9 +97,13 @@ void print_list(struct list_head *list) {
printf(" %8s ", timestamp);
}
printf(" %s\n", ptr->fname);
- /* 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;
+ /* Linux: Neither man stat(2) nor stat(3type) declare why struct stat field st_size
+ * would get a negative value assigned. The type off_t masks __off_t or __off64_t
+ * which themselves mask bits/types.h __SLONGWORD_TYPE on x86_64 that's long int.
+ * Haven't checked libc/kernel code but regardless why, I assume that a negative
+ * value would imply a corrupt filesystem.
+ */
+ total_size += (ptr->ln_stat.st_size>0) ? (unsigned long int)ptr->ln_stat.st_size : 0;
ptr = ptr->next;
}
fputc_all_cols('=', stdout);