aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-23 19:05:11 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-23 19:05:11 +0100
commit2c3131d88e438fff3cc578293e82cc5ffd4693d1 (patch)
tree213601274c69e30c2301a0ce356502256919612c /coreutils
parent5d43ddc59bf62d03cfc0017f24e36533294c455e (diff)
downloadbusybox-w32-2c3131d88e438fff3cc578293e82cc5ffd4693d1.tar.gz
busybox-w32-2c3131d88e438fff3cc578293e82cc5ffd4693d1.tar.bz2
busybox-w32-2c3131d88e438fff3cc578293e82cc5ffd4693d1.zip
ls: LIST_NLINKS/SIZE/DATE_TIME/SYMLINK are always the same, merge as LIST_LOPT
They are always set and cleared together function old new delta append_char 69 68 -1 display_single 910 908 -2 ls_main 677 664 -13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-16) Total: -16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/ls.c64
1 files changed, 30 insertions, 34 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index b138520b3..b7eded73b 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -198,31 +198,27 @@ SPLIT_SUBDIR = 2,
198 198
199/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ 199/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */
200/* what file information will be listed */ 200/* what file information will be listed */
201LIST_MODEBITS = 1 << 2, 201LIST_MODEBITS = 1 << 0,
202LIST_NLINKS = 1 << 3, 202LIST_LOPT = 1 << 1, /* long listing (-l and equivalents) */
203LIST_ID_NAME = 1 << 4, 203LIST_ID_NAME = 1 << 2,
204LIST_ID_NUMERIC = 1 << 5, 204LIST_ID_NUMERIC = 1 << 3,
205LIST_CONTEXT = 1 << 6, 205LIST_CONTEXT = 1 << 4,
206LIST_SIZE = 1 << 7, 206LIST_FULLTIME = 1 << 5,
207LIST_DATE_TIME = 1 << 8, 207LIST_FILETYPE = 1 << 6, /* show / suffix for dirs */
208LIST_FULLTIME = 1 << 9, 208LIST_CLASSIFY = 1 << 7, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */
209LIST_SYMLINK = 1 << 10, 209
210LIST_FILETYPE = 1 << 11, /* show / suffix for dirs */ 210LIST_LONG = LIST_LOPT | LIST_MODEBITS | LIST_ID_NAME,
211LIST_CLASSIFY = 1 << 12, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */
212
213LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \
214 LIST_DATE_TIME | LIST_SYMLINK,
215 211
216/* what files will be displayed */ 212/* what files will be displayed */
217DISP_DIRNAME = 1 << 13, /* 2 or more items? label directories */ 213DISP_DIRNAME = 1 << 8, /* 2 or more items? label directories */
218DISP_NOLIST = 1 << 16, /* show directory as itself, not contents */ 214DISP_NOLIST = 1 << 9, /* show directory as itself, not contents */
219DISP_RECURSIVE = 1 << 17, /* show directory and everything below it */ 215DISP_RECURSIVE = 1 << 10, /* show directory and everything below it */
220DISP_ROWS = 1 << 18, /* print across rows */ 216DISP_ROWS = 1 << 11, /* print across rows */
221 217
222/* what is the overall style of the listing */ 218/* what is the overall style of the listing */
223STYLE_COLUMNAR = 1 << 19, /* many records per line */ 219STYLE_COLUMNAR = 1 << 12, /* many records per line */
224STYLE_LONG = 2 << 19, /* one record per line, extended info */ 220STYLE_LONG = 2 << 12, /* one record per line, extended info */
225STYLE_SINGLE = 3 << 19, /* one record per line */ 221STYLE_SINGLE = 3 << 12, /* one record per line */
226STYLE_MASK = STYLE_SINGLE, 222STYLE_MASK = STYLE_SINGLE,
227}; 223};
228 224
@@ -549,18 +545,18 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
549 /* Do readlink early, so that if it fails, error message 545 /* Do readlink early, so that if it fails, error message
550 * does not appear *inside* the "ls -l" line */ 546 * does not appear *inside* the "ls -l" line */
551 lpath = NULL; 547 lpath = NULL;
552 if (G.all_fmt & LIST_SYMLINK) 548 if (G.all_fmt & LIST_LOPT)
553 if (S_ISLNK(dn->dn_mode)) 549 if (S_ISLNK(dn->dn_mode))
554 lpath = xmalloc_readlink_or_warn(dn->fullname); 550 lpath = xmalloc_readlink_or_warn(dn->fullname);
555 551
556 if (option_mask32 & OPT_i) /* list inodes */ 552 if (option_mask32 & OPT_i) /* show inode# */
557 column += printf("%7llu ", (long long) dn->dn_ino); 553 column += printf("%7llu ", (long long) dn->dn_ino);
558//TODO: -h should affect -s too: 554//TODO: -h should affect -s too:
559 if (option_mask32 & OPT_s) /* list allocated blocks */ 555 if (option_mask32 & OPT_s) /* show allocated blocks */
560 column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); 556 column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
561 if (G.all_fmt & LIST_MODEBITS) 557 if (G.all_fmt & LIST_MODEBITS)
562 column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode)); 558 column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode));
563 if (G.all_fmt & LIST_NLINKS) 559 if (G.all_fmt & LIST_LOPT) /* long listing: show number of links */
564 column += printf("%4lu ", (long) dn->dn_nlink); 560 column += printf("%4lu ", (long) dn->dn_nlink);
565 if (G.all_fmt & LIST_ID_NUMERIC) { 561 if (G.all_fmt & LIST_ID_NUMERIC) {
566 if (option_mask32 & OPT_g) 562 if (option_mask32 & OPT_g)
@@ -582,7 +578,8 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
582 } 578 }
583 } 579 }
584#endif 580#endif
585 if (G.all_fmt & LIST_SIZE) { 581 if (G.all_fmt & LIST_LOPT) {
582 /* long listing: show size */
586 if (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) { 583 if (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) {
587 column += printf("%4u, %3u ", 584 column += printf("%4u, %3u ",
588 dn->dn_rdev_maj, 585 dn->dn_rdev_maj,
@@ -597,23 +594,22 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
597 column += printf("%9"OFF_FMT"u ", dn->dn_size); 594 column += printf("%9"OFF_FMT"u ", dn->dn_size);
598 } 595 }
599 } 596 }
600 }
601#if ENABLE_FEATURE_LS_TIMESTAMPS 597#if ENABLE_FEATURE_LS_TIMESTAMPS
602 if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) { 598 /* long listing: show {m,c,a}time */
603 const time_t *ttime = &dn->dn_time;
604 if (G.all_fmt & LIST_FULLTIME) { /* --full-time */ 599 if (G.all_fmt & LIST_FULLTIME) { /* --full-time */
605 /* coreutils 8.4 ls --full-time prints: 600 /* coreutils 8.4 ls --full-time prints:
606 * 2009-07-13 17:49:27.000000000 +0200 601 * 2009-07-13 17:49:27.000000000 +0200
607 * we don't show fractional seconds. 602 * we don't show fractional seconds.
608 */ 603 */
609 char buf[sizeof("YYYY-mm-dd HH:MM:SS TIMEZONE")]; 604 char buf[sizeof("YYYY-mm-dd HH:MM:SS TIMEZONE")];
610 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z", localtime(ttime)); 605 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z",
606 localtime(&dn->dn_time));
611 column += printf("%s ", buf); 607 column += printf("%s ", buf);
612 } else { /* LIST_DATE_TIME */ 608 } else { /* ordinary time format */
613 /* G.current_time_t is ~== time(NULL) */ 609 /* G.current_time_t is ~== time(NULL) */
614 char *filetime = ctime(ttime); 610 char *filetime = ctime(&dn->dn_time);
615 /* filetime's format: "Wed Jun 30 21:49:08 1993\n" */ 611 /* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
616 time_t age = G.current_time_t - *ttime; 612 time_t age = G.current_time_t - dn->dn_time;
617 if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { 613 if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
618 /* less than 6 months old */ 614 /* less than 6 months old */
619 /* "mmm dd hh:mm " */ 615 /* "mmm dd hh:mm " */
@@ -626,8 +622,8 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
626 } 622 }
627 column += 13; 623 column += 13;
628 } 624 }
629 }
630#endif 625#endif
626 }
631#if ENABLE_SELINUX 627#if ENABLE_SELINUX
632 if (G.all_fmt & LIST_CONTEXT) { 628 if (G.all_fmt & LIST_CONTEXT) {
633 column += printf("%-32s ", dn->sid ? dn->sid : "unknown"); 629 column += printf("%-32s ", dn->sid ? dn->sid : "unknown");