aboutsummaryrefslogtreecommitdiff
path: root/coreutils/ls.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r--coreutils/ls.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 1b63be56d..14c8beaff 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -566,12 +566,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
566#if ENABLE_FEATURE_LS_TIMESTAMPS 566#if ENABLE_FEATURE_LS_TIMESTAMPS
567 if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) { 567 if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) {
568 char *filetime; 568 char *filetime;
569 time_t ttime = dn->dn_mtime; 569 const time_t *ttime = &dn->dn_mtime;
570 if (G.all_fmt & TIME_ACCESS) 570 if (G.all_fmt & TIME_ACCESS)
571 ttime = dn->dn_atime; 571 ttime = &dn->dn_atime;
572 if (G.all_fmt & TIME_CHANGE) 572 if (G.all_fmt & TIME_CHANGE)
573 ttime = dn->dn_ctime; 573 ttime = &dn->dn_ctime;
574 filetime = ctime(&ttime); 574 filetime = ctime(ttime);
575 /* filetime's format: "Wed Jun 30 21:49:08 1993\n" */ 575 /* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
576 if (G.all_fmt & LIST_FULLTIME) { /* -e */ 576 if (G.all_fmt & LIST_FULLTIME) { /* -e */
577 /* Note: coreutils 8.4 ls --full-time prints: 577 /* Note: coreutils 8.4 ls --full-time prints:
@@ -580,13 +580,16 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
580 column += printf("%.24s ", filetime); 580 column += printf("%.24s ", filetime);
581 } else { /* LIST_DATE_TIME */ 581 } else { /* LIST_DATE_TIME */
582 /* G.current_time_t ~== time(NULL) */ 582 /* G.current_time_t ~== time(NULL) */
583 time_t age = G.current_time_t - ttime; 583 time_t age = G.current_time_t - *ttime;
584 printf("%.6s ", filetime + 4); /* "Jun 30" */
585 if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { 584 if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
586 /* hh:mm if less than 6 months old */ 585 /* less than 6 months old */
587 printf("%.5s ", filetime + 11); 586 /* "mmm dd hh:mm " */
588 } else { /* year. buggy if year > 9999 ;) */ 587 printf("%.12s ", filetime + 4);
589 printf(" %.4s ", filetime + 20); 588 } else {
589 /* "mmm dd yyyy " */
590 /* "mmm dd yyyyy " after year 9999 :) */
591 strchr(filetime + 20, '\n')[0] = ' ';
592 printf("%.7s%6s", filetime + 4, filetime + 20);
590 } 593 }
591 column += 13; 594 column += 13;
592 } 595 }