From 923690add35ef0c62cc169afbb651a6957eb75c2 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 11 Apr 2022 18:39:30 -0400 Subject: fix sort by size and printing times --- ls.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ls.c b/ls.c index e9d9d85..cad7347 100644 --- a/ls.c +++ b/ls.c @@ -112,7 +112,7 @@ static int ls_compare_files(const void *op_a, const void *op_b) int ret = 0; switch (sort) { case SIZE: - ret = a->st.st_size - b->st.st_size; + ret = b->st.st_size - a->st.st_size; break; case CTIME: @@ -353,7 +353,13 @@ static void ls_print_long(size_t n, struct file_info files[static n]) printf("%*ju ", SIZEWIDTH, (uintmax_t)st.st_size); } - printf("%s ", ls_file_time(st.st_mtim)); + if (sort == ATIME) { + printf("%s ", ls_file_time(st.st_atim)); + } else if (sort == CTIME) { + printf("%s ", ls_file_time(st.st_ctim)); + } else { + printf("%s ", ls_file_time(st.st_mtim)); + } char * name = ls_filename(files + i); if (S_ISLNK(st.st_mode)) { -- cgit v1.2.1