diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-23 19:42:12 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-23 19:42:12 +0100 |
commit | 51b01fda30418e4114a63be3db8ab0135dea12fc (patch) | |
tree | e4af168b2de4f54d0e98d75c2e2d066aabe5f834 /coreutils/ls.c | |
parent | a1cbaca1ba6f4a3ffc7727fcd4c4ebb61c47e1a7 (diff) | |
download | busybox-w32-51b01fda30418e4114a63be3db8ab0135dea12fc.tar.gz busybox-w32-51b01fda30418e4114a63be3db8ab0135dea12fc.tar.bz2 busybox-w32-51b01fda30418e4114a63be3db8ab0135dea12fc.zip |
ls: LIST_ID_NAME/ID_NUMERIC/LOPT/LONG are the same, merge as LONG
Also, handle -n and --full-time using option_mask32
function old new delta
scan_and_display_dirs_recur 548 545 -3
display_single 1053 1039 -14
ls_main 777 736 -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-58) Total: -58 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r-- | coreutils/ls.c | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 70118b1b2..77fc530d8 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -197,32 +197,27 @@ SPLIT_SUBDIR = 2, | |||
197 | 197 | ||
198 | /* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ | 198 | /* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ |
199 | /* what file information will be listed */ | 199 | /* what file information will be listed */ |
200 | LIST_LOPT = 1 << 1, /* long listing (-l and equivalents) */ | 200 | LIST_LONG = 1 << 0, /* long listing (-l and equivalents) */ |
201 | LIST_ID_NAME = 1 << 2, | 201 | LIST_FILETYPE = 1 << 1, /* show / suffix for dirs */ |
202 | LIST_ID_NUMERIC = 1 << 3, | 202 | LIST_CLASSIFY = 1 << 2, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */ |
203 | LIST_FULLTIME = 1 << 5, | ||
204 | LIST_FILETYPE = 1 << 6, /* show / suffix for dirs */ | ||
205 | LIST_CLASSIFY = 1 << 7, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */ | ||
206 | |||
207 | LIST_LONG = LIST_LOPT | LIST_ID_NAME, | ||
208 | 203 | ||
209 | /* what files will be displayed */ | 204 | /* what files will be displayed */ |
210 | DISP_DIRNAME = 1 << 8, /* 2 or more items? label directories */ | 205 | DISP_DIRNAME = 1 << 3, /* 2 or more items? label directories */ |
211 | DISP_NOLIST = 1 << 9, /* show directory as itself, not contents */ | 206 | DISP_NOLIST = 1 << 4, /* show directory as itself, not contents */ |
212 | DISP_RECURSIVE = 1 << 10, /* show directory and everything below it */ | 207 | DISP_RECURSIVE = 1 << 5, /* show directory and everything below it */ |
213 | DISP_ROWS = 1 << 11, /* print across rows */ | 208 | DISP_ROWS = 1 << 6, /* print across rows */ |
214 | 209 | ||
215 | /* what is the overall style of the listing */ | 210 | /* what is the overall style of the listing */ |
216 | STYLE_COLUMNAR = 1 << 12, /* many records per line */ | 211 | STYLE_COLUMNAR = 1 << 7, /* many records per line */ |
217 | STYLE_LONG = 2 << 12, /* one record per line, extended info */ | 212 | STYLE_LONG = 2 << 8, /* one record per line, extended info */ |
218 | STYLE_SINGLE = 3 << 12, /* one record per line */ | 213 | STYLE_SINGLE = 3 << 9, /* one record per line */ |
219 | STYLE_MASK = STYLE_SINGLE, | 214 | STYLE_MASK = STYLE_SINGLE, |
220 | }; | 215 | }; |
221 | 216 | ||
222 | /* -Cadi1l Std options, busybox always supports */ | 217 | /* -Cadi1l Std options, busybox always supports */ |
223 | /* -gnsxA Std options, busybox always supports */ | 218 | /* -gnsxA Std options, busybox always supports */ |
224 | /* -Q GNU option, busybox always supports */ | 219 | /* -Q GNU option, busybox always supports */ |
225 | /* -k Std options, busybox always supports (by ignoring) */ | 220 | /* -k Std option, busybox always supports (by ignoring) */ |
226 | /* It means "for -s, show sizes in kbytes" */ | 221 | /* It means "for -s, show sizes in kbytes" */ |
227 | /* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */ | 222 | /* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */ |
228 | /* since otherwise -s shows kbytes anyway */ | 223 | /* since otherwise -s shows kbytes anyway */ |
@@ -251,7 +246,7 @@ enum { | |||
251 | //OPT_1 = (1 << 4), | 246 | //OPT_1 = (1 << 4), |
252 | OPT_l = (1 << 5), | 247 | OPT_l = (1 << 5), |
253 | OPT_g = (1 << 6), | 248 | OPT_g = (1 << 6), |
254 | //OPT_n = (1 << 7), | 249 | OPT_n = (1 << 7), |
255 | OPT_s = (1 << 8), | 250 | OPT_s = (1 << 8), |
256 | //OPT_x = (1 << 9), | 251 | //OPT_x = (1 << 9), |
257 | OPT_A = (1 << 10), | 252 | OPT_A = (1 << 10), |
@@ -310,7 +305,7 @@ static const uint32_t opt_flags[] = { | |||
310 | STYLE_SINGLE, /* 1 */ | 305 | STYLE_SINGLE, /* 1 */ |
311 | LIST_LONG | STYLE_LONG, /* l - by keeping it after -1, "ls -l -1" ignores -1 */ | 306 | LIST_LONG | STYLE_LONG, /* l - by keeping it after -1, "ls -l -1" ignores -1 */ |
312 | LIST_LONG | STYLE_LONG, /* g (don't show owner) - handled via OPT_g. assumes l */ | 307 | LIST_LONG | STYLE_LONG, /* g (don't show owner) - handled via OPT_g. assumes l */ |
313 | LIST_LONG | STYLE_LONG | LIST_ID_NUMERIC, /* n (assumes l) */ | 308 | LIST_LONG | STYLE_LONG, /* n (numeris uid/gid) - handled via OPT_n. assumes l */ |
314 | 0, /* s */ | 309 | 0, /* s */ |
315 | DISP_ROWS | STYLE_COLUMNAR, /* x */ | 310 | DISP_ROWS | STYLE_COLUMNAR, /* x */ |
316 | 0, /* A */ | 311 | 0, /* A */ |
@@ -542,7 +537,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn) | |||
542 | /* Do readlink early, so that if it fails, error message | 537 | /* Do readlink early, so that if it fails, error message |
543 | * does not appear *inside* the "ls -l" line */ | 538 | * does not appear *inside* the "ls -l" line */ |
544 | lpath = NULL; | 539 | lpath = NULL; |
545 | if (G.all_fmt & LIST_LOPT) | 540 | if (G.all_fmt & LIST_LONG) |
546 | if (S_ISLNK(dn->dn_mode)) | 541 | if (S_ISLNK(dn->dn_mode)) |
547 | lpath = xmalloc_readlink_or_warn(dn->fullname); | 542 | lpath = xmalloc_readlink_or_warn(dn->fullname); |
548 | 543 | ||
@@ -551,39 +546,40 @@ static NOINLINE unsigned display_single(const struct dnode *dn) | |||
551 | //TODO: -h should affect -s too: | 546 | //TODO: -h should affect -s too: |
552 | if (option_mask32 & OPT_s) /* show allocated blocks */ | 547 | if (option_mask32 & OPT_s) /* show allocated blocks */ |
553 | column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); | 548 | column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); |
554 | if (G.all_fmt & LIST_LOPT) { | 549 | if (G.all_fmt & LIST_LONG) { |
555 | /* long listing: show mode */ | 550 | /* long listing: show mode */ |
556 | column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode)); | 551 | column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode)); |
557 | /* long listing: show number of links */ | 552 | /* long listing: show number of links */ |
558 | column += printf("%4lu ", (long) dn->dn_nlink); | 553 | column += printf("%4lu ", (long) dn->dn_nlink); |
559 | } | 554 | /* long listing: show user/group */ |
560 | if (G.all_fmt & LIST_ID_NUMERIC) { | 555 | if (option_mask32 & OPT_n) { |
561 | if (option_mask32 & OPT_g) | 556 | if (option_mask32 & OPT_g) |
562 | column += printf("%-8u ", (int) dn->dn_gid); | 557 | column += printf("%-8u ", (int) dn->dn_gid); |
563 | else | 558 | else |
564 | column += printf("%-8u %-8u ", | 559 | column += printf("%-8u %-8u ", |
565 | (int) dn->dn_uid, | 560 | (int) dn->dn_uid, |
566 | (int) dn->dn_gid); | 561 | (int) dn->dn_gid); |
567 | } | 562 | } |
568 | #if ENABLE_FEATURE_LS_USERNAME | 563 | #if ENABLE_FEATURE_LS_USERNAME |
569 | else if (G.all_fmt & LIST_ID_NAME) { | 564 | else { |
570 | if (option_mask32 & OPT_g) { | 565 | if (option_mask32 & OPT_g) { |
571 | column += printf("%-8.8s ", | 566 | column += printf("%-8.8s ", |
572 | get_cached_groupname(dn->dn_gid)); | 567 | get_cached_groupname(dn->dn_gid)); |
573 | } else { | 568 | } else { |
574 | column += printf("%-8.8s %-8.8s ", | 569 | column += printf("%-8.8s %-8.8s ", |
575 | get_cached_username(dn->dn_uid), | 570 | get_cached_username(dn->dn_uid), |
576 | get_cached_groupname(dn->dn_gid)); | 571 | get_cached_groupname(dn->dn_gid)); |
572 | } | ||
577 | } | 573 | } |
578 | } | ||
579 | #endif | 574 | #endif |
580 | #if ENABLE_SELINUX | 575 | #if ENABLE_SELINUX |
576 | } | ||
581 | if (option_mask32 & OPT_Z) { | 577 | if (option_mask32 & OPT_Z) { |
582 | column += printf("%-32s ", dn->sid ? dn->sid : "?"); | 578 | column += printf("%-32s ", dn->sid ? dn->sid : "?"); |
583 | freecon(dn->sid); | 579 | freecon(dn->sid); |
584 | } | 580 | } |
581 | if (G.all_fmt & LIST_LONG) { | ||
585 | #endif | 582 | #endif |
586 | if (G.all_fmt & LIST_LOPT) { | ||
587 | /* long listing: show size */ | 583 | /* long listing: show size */ |
588 | if (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) { | 584 | if (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) { |
589 | column += printf("%4u, %3u ", | 585 | column += printf("%4u, %3u ", |
@@ -601,7 +597,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn) | |||
601 | } | 597 | } |
602 | #if ENABLE_FEATURE_LS_TIMESTAMPS | 598 | #if ENABLE_FEATURE_LS_TIMESTAMPS |
603 | /* long listing: show {m,c,a}time */ | 599 | /* long listing: show {m,c,a}time */ |
604 | if (G.all_fmt & LIST_FULLTIME) { /* --full-time */ | 600 | if (option_mask32 & OPT_full_time) { /* --full-time */ |
605 | /* coreutils 8.4 ls --full-time prints: | 601 | /* coreutils 8.4 ls --full-time prints: |
606 | * 2009-07-13 17:49:27.000000000 +0200 | 602 | * 2009-07-13 17:49:27.000000000 +0200 |
607 | * we don't show fractional seconds. | 603 | * we don't show fractional seconds. |
@@ -1187,8 +1183,6 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1187 | option_mask32 &= ~OPT_Z; | 1183 | option_mask32 &= ~OPT_Z; |
1188 | } | 1184 | } |
1189 | #endif | 1185 | #endif |
1190 | if (opt & OPT_full_time) | ||
1191 | G.all_fmt |= LIST_FULLTIME; | ||
1192 | 1186 | ||
1193 | #if ENABLE_FEATURE_LS_COLOR | 1187 | #if ENABLE_FEATURE_LS_COLOR |
1194 | /* set G_show_color = 1/0 */ | 1188 | /* set G_show_color = 1/0 */ |
@@ -1219,7 +1213,6 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1219 | if (ENABLE_FEATURE_LS_RECURSIVE && (G.all_fmt & DISP_NOLIST)) | 1213 | if (ENABLE_FEATURE_LS_RECURSIVE && (G.all_fmt & DISP_NOLIST)) |
1220 | G.all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */ | 1214 | G.all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */ |
1221 | if ((G.all_fmt & STYLE_MASK) != STYLE_LONG) { /* not -l? */ | 1215 | if ((G.all_fmt & STYLE_MASK) != STYLE_LONG) { /* not -l? */ |
1222 | G.all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME); | ||
1223 | if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) { | 1216 | if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) { |
1224 | /* when to sort by time? -t[cu] sorts by time even with -l */ | 1217 | /* when to sort by time? -t[cu] sorts by time even with -l */ |
1225 | /* (this is achieved by opt_flags[] element for -t) */ | 1218 | /* (this is achieved by opt_flags[] element for -t) */ |