diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-18 01:55:00 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-18 01:55:00 +0100 |
commit | 9c3b84a3049a152dd6a2b9e3aecaf897f57ac28e (patch) | |
tree | 97a510f4effe3a9d074db41c0996b8e74b216811 /coreutils | |
parent | b972f949577301bd7a66e88c11b9e26431d80a11 (diff) | |
download | busybox-w32-9c3b84a3049a152dd6a2b9e3aecaf897f57ac28e.tar.gz busybox-w32-9c3b84a3049a152dd6a2b9e3aecaf897f57ac28e.tar.bz2 busybox-w32-9c3b84a3049a152dd6a2b9e3aecaf897f57ac28e.zip |
ls: make it so that group never glues itself to file size
+ smaller enhancements: inode is long long; -h is a bit narrower; etc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/ls.c | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 5ea3a0b27..153977f3f 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -761,10 +761,6 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |||
761 | { | 761 | { |
762 | unsigned column = 0; | 762 | unsigned column = 0; |
763 | char *lpath = lpath; /* for compiler */ | 763 | char *lpath = lpath; /* for compiler */ |
764 | #if ENABLE_FEATURE_LS_TIMESTAMPS | ||
765 | char *filetime; | ||
766 | time_t ttime, age; | ||
767 | #endif | ||
768 | #if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR | 764 | #if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR |
769 | struct stat info; | 765 | struct stat info; |
770 | char append; | 766 | char append; |
@@ -775,28 +771,20 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |||
775 | return 0; | 771 | return 0; |
776 | */ | 772 | */ |
777 | 773 | ||
778 | #if ENABLE_FEATURE_LS_TIMESTAMPS | ||
779 | ttime = dn->dstat.st_mtime; /* the default time */ | ||
780 | if (all_fmt & TIME_ACCESS) | ||
781 | ttime = dn->dstat.st_atime; | ||
782 | if (all_fmt & TIME_CHANGE) | ||
783 | ttime = dn->dstat.st_ctime; | ||
784 | filetime = ctime(&ttime); | ||
785 | #endif | ||
786 | #if ENABLE_FEATURE_LS_FILETYPES | 774 | #if ENABLE_FEATURE_LS_FILETYPES |
787 | append = append_char(dn->dstat.st_mode); | 775 | append = append_char(dn->dstat.st_mode); |
788 | #endif | 776 | #endif |
789 | 777 | ||
790 | /* Do readlink early, so that if it fails, error message | 778 | /* Do readlink early, so that if it fails, error message |
791 | * does not appear *inside* of the "ls -l" line */ | 779 | * does not appear *inside* the "ls -l" line */ |
792 | if (all_fmt & LIST_SYMLINK) | 780 | if (all_fmt & LIST_SYMLINK) |
793 | if (S_ISLNK(dn->dstat.st_mode)) | 781 | if (S_ISLNK(dn->dstat.st_mode)) |
794 | lpath = xmalloc_readlink_or_warn(dn->fullname); | 782 | lpath = xmalloc_readlink_or_warn(dn->fullname); |
795 | 783 | ||
796 | if (all_fmt & LIST_INO) | 784 | if (all_fmt & LIST_INO) |
797 | column += printf("%7lu ", (long) dn->dstat.st_ino); | 785 | column += printf("%7llu ", (long long) dn->dstat.st_ino); |
798 | if (all_fmt & LIST_BLOCKS) | 786 | if (all_fmt & LIST_BLOCKS) |
799 | column += printf("%4"OFF_FMT"u ", (off_t) dn->dstat.st_blocks >> 1); | 787 | column += printf("%4"OFF_FMT"u ", (off_t) (dn->dstat.st_blocks >> 1)); |
800 | if (all_fmt & LIST_MODEBITS) | 788 | if (all_fmt & LIST_MODEBITS) |
801 | column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode)); | 789 | column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode)); |
802 | if (all_fmt & LIST_NLINKS) | 790 | if (all_fmt & LIST_NLINKS) |
@@ -804,10 +792,10 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |||
804 | #if ENABLE_FEATURE_LS_USERNAME | 792 | #if ENABLE_FEATURE_LS_USERNAME |
805 | if (all_fmt & LIST_ID_NAME) { | 793 | if (all_fmt & LIST_ID_NAME) { |
806 | if (option_mask32 & OPT_g) { | 794 | if (option_mask32 & OPT_g) { |
807 | column += printf("%-8.8s", | 795 | column += printf("%-8.8s ", |
808 | get_cached_username(dn->dstat.st_uid)); | 796 | get_cached_username(dn->dstat.st_uid)); |
809 | } else { | 797 | } else { |
810 | column += printf("%-8.8s %-8.8s", | 798 | column += printf("%-8.8s %-8.8s ", |
811 | get_cached_username(dn->dstat.st_uid), | 799 | get_cached_username(dn->dstat.st_uid), |
812 | get_cached_groupname(dn->dstat.st_gid)); | 800 | get_cached_groupname(dn->dstat.st_gid)); |
813 | } | 801 | } |
@@ -815,9 +803,9 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |||
815 | #endif | 803 | #endif |
816 | if (all_fmt & LIST_ID_NUMERIC) { | 804 | if (all_fmt & LIST_ID_NUMERIC) { |
817 | if (option_mask32 & OPT_g) | 805 | if (option_mask32 & OPT_g) |
818 | column += printf("%-8u", (int) dn->dstat.st_uid); | 806 | column += printf("%-8u ", (int) dn->dstat.st_uid); |
819 | else | 807 | else |
820 | column += printf("%-8u %-8u", | 808 | column += printf("%-8u %-8u ", |
821 | (int) dn->dstat.st_uid, | 809 | (int) dn->dstat.st_uid, |
822 | (int) dn->dstat.st_gid); | 810 | (int) dn->dstat.st_gid); |
823 | } | 811 | } |
@@ -828,7 +816,7 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |||
828 | (int) minor(dn->dstat.st_rdev)); | 816 | (int) minor(dn->dstat.st_rdev)); |
829 | } else { | 817 | } else { |
830 | if (all_fmt & LS_DISP_HR) { | 818 | if (all_fmt & LS_DISP_HR) { |
831 | column += printf("%9s ", | 819 | column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ", |
832 | /* print st_size, show one fractional, use suffixes */ | 820 | /* print st_size, show one fractional, use suffixes */ |
833 | make_human_readable_str(dn->dstat.st_size, 1, 0) | 821 | make_human_readable_str(dn->dstat.st_size, 1, 0) |
834 | ); | 822 | ); |
@@ -838,21 +826,30 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |||
838 | } | 826 | } |
839 | } | 827 | } |
840 | #if ENABLE_FEATURE_LS_TIMESTAMPS | 828 | #if ENABLE_FEATURE_LS_TIMESTAMPS |
841 | if (all_fmt & LIST_FULLTIME) | 829 | if (all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) { |
842 | column += printf("%24.24s ", filetime); | 830 | char *filetime; |
843 | if (all_fmt & LIST_DATE_TIME) | 831 | time_t ttime = dn->dstat.st_mtime; |
844 | if ((all_fmt & LIST_FULLTIME) == 0) { | 832 | if (all_fmt & TIME_ACCESS) |
833 | ttime = dn->dstat.st_atime; | ||
834 | if (all_fmt & TIME_CHANGE) | ||
835 | ttime = dn->dstat.st_ctime; | ||
836 | filetime = ctime(&ttime); | ||
837 | /* filetime's format: "Wed Jun 30 21:49:08 1993\n" */ | ||
838 | if (all_fmt & LIST_FULLTIME) | ||
839 | column += printf("%.24s ", filetime); | ||
840 | else { /* LIST_DATE_TIME */ | ||
845 | /* current_time_t ~== time(NULL) */ | 841 | /* current_time_t ~== time(NULL) */ |
846 | age = current_time_t - ttime; | 842 | time_t age = current_time_t - ttime; |
847 | printf("%6.6s ", filetime + 4); | 843 | printf("%.6s ", filetime + 4); /* "Jun 30" */ |
848 | if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { | 844 | if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { |
849 | /* hh:mm if less than 6 months old */ | 845 | /* hh:mm if less than 6 months old */ |
850 | printf("%5.5s ", filetime + 11); | 846 | printf("%.5s ", filetime + 11); |
851 | } else { | 847 | } else { /* year. buggy if year > 9999 ;) */ |
852 | printf(" %4.4s ", filetime + 20); | 848 | printf(" %.4s ", filetime + 20); |
853 | } | 849 | } |
854 | column += 13; | 850 | column += 13; |
855 | } | 851 | } |
852 | } | ||
856 | #endif | 853 | #endif |
857 | #if ENABLE_SELINUX | 854 | #if ENABLE_SELINUX |
858 | if (all_fmt & LIST_CONTEXT) { | 855 | if (all_fmt & LIST_CONTEXT) { |