aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-19 22:03:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-19 22:03:06 +0000
commite0554434126541e943bf0f1d90a475252392bf6f (patch)
treec244a24fb16b372f155129656d6c14e2fccae775
parent4ebaf1074218d4e1c2907114bc53080c5abbd57d (diff)
downloadbusybox-w32-e0554434126541e943bf0f1d90a475252392bf6f.tar.gz
busybox-w32-e0554434126541e943bf0f1d90a475252392bf6f.tar.bz2
busybox-w32-e0554434126541e943bf0f1d90a475252392bf6f.zip
ls: stop doing time() for each file in "ls -l"
ls: use fully-buffered stdout (can it be problematic on VERY slow/hanging NFS mounts?)
-rw-r--r--coreutils/ls.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index ff0831dac..067e463ee 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -537,6 +537,12 @@ static struct dnode **list_dir(const char *path)
537} 537}
538 538
539 539
540#if ENABLE_FEATURE_LS_TIMESTAMPS
541/* Do time() just once. Saves one syscall per file for "ls -l" */
542/* Initialized in main() */
543static time_t current_time_t;
544#endif
545
540static int list_single(struct dnode *dn) 546static int list_single(struct dnode *dn)
541{ 547{
542 int i, column = 0; 548 int i, column = 0;
@@ -611,7 +617,8 @@ static int list_single(struct dnode *dn)
611 break; 617 break;
612 case LIST_DATE_TIME: 618 case LIST_DATE_TIME:
613 if ((all_fmt & LIST_FULLTIME) == 0) { 619 if ((all_fmt & LIST_FULLTIME) == 0) {
614 age = time(NULL) - ttime; 620 /* current_time_t ~== time(NULL) */
621 age = current_time_t - ttime;
615 printf("%6.6s ", filetime + 4); 622 printf("%6.6s ", filetime + 4);
616 if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { 623 if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
617 /* hh:mm if less than 6 months old */ 624 /* hh:mm if less than 6 months old */
@@ -785,6 +792,12 @@ int ls_main(int argc, char **argv)
785 USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;) 792 USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;)
786 USE_FEATURE_LS_COLOR(char *color_opt;) 793 USE_FEATURE_LS_COLOR(char *color_opt;)
787 794
795 setvbuf(stdout, bb_common_bufsiz1, _IOFBF, BUFSIZ);
796
797#if ENABLE_FEATURE_LS_TIMESTAMPS
798 time(&current_time_t);
799#endif
800
788 all_fmt = LIST_SHORT | 801 all_fmt = LIST_SHORT |
789 (ENABLE_FEATURE_LS_SORTFILES * (SORT_NAME | SORT_FORWARD)); 802 (ENABLE_FEATURE_LS_SORTFILES * (SORT_NAME | SORT_FORWARD));
790 803