diff options
author | Denis Vlasenko | 2007-01-19 22:03:06 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-01-19 22:03:06 +0000 |
commit | e0554434126541e943bf0f1d90a475252392bf6f (patch) | |
tree | c244a24fb16b372f155129656d6c14e2fccae775 /coreutils | |
parent | 4ebaf1074218d4e1c2907114bc53080c5abbd57d (diff) | |
download | busybox-e0554434126541e943bf0f1d90a475252392bf6f.zip busybox-e0554434126541e943bf0f1d90a475252392bf6f.tar.gz |
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?)
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/ls.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index ff0831d..067e463 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -537,6 +537,12 @@ static struct dnode **list_dir(const char *path) } +#if ENABLE_FEATURE_LS_TIMESTAMPS +/* Do time() just once. Saves one syscall per file for "ls -l" */ +/* Initialized in main() */ +static time_t current_time_t; +#endif + static int list_single(struct dnode *dn) { int i, column = 0; @@ -611,7 +617,8 @@ static int list_single(struct dnode *dn) break; case LIST_DATE_TIME: if ((all_fmt & LIST_FULLTIME) == 0) { - age = time(NULL) - ttime; + /* current_time_t ~== time(NULL) */ + age = current_time_t - ttime; printf("%6.6s ", filetime + 4); if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { /* hh:mm if less than 6 months old */ @@ -785,6 +792,12 @@ int ls_main(int argc, char **argv) USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;) USE_FEATURE_LS_COLOR(char *color_opt;) + setvbuf(stdout, bb_common_bufsiz1, _IOFBF, BUFSIZ); + +#if ENABLE_FEATURE_LS_TIMESTAMPS + time(¤t_time_t); +#endif + all_fmt = LIST_SHORT | (ENABLE_FEATURE_LS_SORTFILES * (SORT_NAME | SORT_FORWARD)); |