diff options
author | Richard June <rjune@bravegnuworld.com> | 2001-01-22 22:35:38 +0000 |
---|---|---|
committer | Richard June <rjune@bravegnuworld.com> | 2001-01-22 22:35:38 +0000 |
commit | 6d0921cc0bb01b1d090285c487f8c1120dfa5d3a (patch) | |
tree | 97ed53aec9cbe3a3021804e9758abb3e04f05879 | |
parent | 3b3f5c364a486dc2c081f0684a4315740f349be1 (diff) | |
download | busybox-w32-6d0921cc0bb01b1d090285c487f8c1120dfa5d3a.tar.gz busybox-w32-6d0921cc0bb01b1d090285c487f8c1120dfa5d3a.tar.bz2 busybox-w32-6d0921cc0bb01b1d090285c487f8c1120dfa5d3a.zip |
Add HUMAN_READABLE define for -m and -h support in du, df, and ls
Add support for -k in du, df, and ls(no define, it's for compatibliity with the GNU utils as bb does -k by default)
Fix bug #1084
-rw-r--r-- | Config.h | 3 | ||||
-rw-r--r-- | applets/usage.c | 42 | ||||
-rw-r--r-- | busybox.h | 7 | ||||
-rw-r--r-- | coreutils/df.c | 68 | ||||
-rw-r--r-- | coreutils/du.c | 26 | ||||
-rw-r--r-- | coreutils/ls.c | 31 | ||||
-rw-r--r-- | df.c | 68 | ||||
-rw-r--r-- | du.c | 26 | ||||
-rw-r--r-- | include/busybox.h | 7 | ||||
-rw-r--r-- | ls.c | 31 | ||||
-rw-r--r-- | usage.c | 42 | ||||
-rw-r--r-- | utility.c | 21 |
12 files changed, 330 insertions, 42 deletions
@@ -290,6 +290,9 @@ | |||
290 | // have a really good reason for cleaning things up manually. | 290 | // have a really good reason for cleaning things up manually. |
291 | //#define BB_FEATURE_CLEAN_UP | 291 | //#define BB_FEATURE_CLEAN_UP |
292 | // | 292 | // |
293 | // Support for human readable output by ls, du, etc.(example 13k, 23M, 235G) | ||
294 | #define BB_FEATURE_HUMAN_READABLE | ||
295 | // | ||
293 | // End of Features List | 296 | // End of Features List |
294 | // | 297 | // |
295 | // | 298 | // |
diff --git a/applets/usage.c b/applets/usage.c index 864891797..9ae2bb3ef 100644 --- a/applets/usage.c +++ b/applets/usage.c | |||
@@ -190,9 +190,22 @@ const char deallocvt_usage[] = | |||
190 | 190 | ||
191 | #if defined BB_DF | 191 | #if defined BB_DF |
192 | const char df_usage[] = | 192 | const char df_usage[] = |
193 | "df [filesystem ...]" | 193 | "df [-?" |
194 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
195 | "hm" | ||
196 | #endif | ||
197 | "k] [filesystem ...]\n" | ||
194 | #ifndef BB_FEATURE_TRIVIAL_HELP | 198 | #ifndef BB_FEATURE_TRIVIAL_HELP |
195 | "\n\nPrint the filesystem space used and space available." | 199 | "\n\nPrint the filesystem space used and space available." |
200 | "Options:\n" | ||
201 | "\t-?\tshow usage information\n" | ||
202 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
203 | "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" | ||
204 | "\t-m\tprint sizes in megabytes\n" | ||
205 | "\t-k\tprint sizes in kilobytes(default)\n" | ||
206 | #else | ||
207 | "\t-k\tprint sizes in kilobytes(compatability)\n" | ||
208 | #endif | ||
196 | #endif | 209 | #endif |
197 | ; | 210 | ; |
198 | #endif | 211 | #endif |
@@ -244,13 +257,25 @@ const char dpkg_deb_usage[] = | |||
244 | 257 | ||
245 | #if defined BB_DU | 258 | #if defined BB_DU |
246 | const char du_usage[] = | 259 | const char du_usage[] = |
247 | "du [OPTION]... [FILE]..." | 260 | "du [-?ls" |
261 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
262 | "hm" | ||
263 | #endif | ||
264 | "k] [FILE]...\n" | ||
248 | #ifndef BB_FEATURE_TRIVIAL_HELP | 265 | #ifndef BB_FEATURE_TRIVIAL_HELP |
249 | "\n\nSummarizes disk space used for each FILE and/or directory.\n" | 266 | "\n\nSummarizes disk space used for each FILE and/or directory.\n" |
250 | "Disk space is printed in units of 1024 bytes.\n\n" | 267 | "Disk space is printed in units of 1024 bytes.\n\n" |
251 | "Options:\n" | 268 | "Options:\n" |
269 | "\t-?\tshow usage information\n" | ||
252 | "\t-l\tcount sizes many times if hard linked\n" | 270 | "\t-l\tcount sizes many times if hard linked\n" |
253 | "\t-s\tdisplay only a total for each argument" | 271 | "\t-s\tdisplay only a total for each argument" |
272 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
273 | "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" | ||
274 | "\t-m\tprint sizes in megabytes\n" | ||
275 | "\t-k\tprint sizes in kilobytes(default)\n" | ||
276 | #else | ||
277 | "\t-k\tprint sizes in kilobytes(compatability)\n" | ||
278 | #endif | ||
254 | #endif | 279 | #endif |
255 | ; | 280 | ; |
256 | #endif | 281 | #endif |
@@ -661,7 +686,10 @@ const char ls_usage[] = | |||
661 | #ifdef BB_FEATURE_LS_SORTFILES | 686 | #ifdef BB_FEATURE_LS_SORTFILES |
662 | "X" | 687 | "X" |
663 | #endif | 688 | #endif |
664 | "] [filenames...]" | 689 | #ifdef BB_FEATURE_HUMAN_READABLE |
690 | "h" | ||
691 | #endif | ||
692 | "k] [filenames...]\n" | ||
665 | #ifndef BB_FEATURE_TRIVIAL_HELP | 693 | #ifndef BB_FEATURE_TRIVIAL_HELP |
666 | "\n\nList directory contents\n\n" | 694 | "\n\nList directory contents\n\n" |
667 | "Options:\n" | 695 | "Options:\n" |
@@ -716,6 +744,14 @@ const char ls_usage[] = | |||
716 | #ifdef BB_FEATURE_LS_SORTFILES | 744 | #ifdef BB_FEATURE_LS_SORTFILES |
717 | "\t-X\tsort the listing by extension\n" | 745 | "\t-X\tsort the listing by extension\n" |
718 | #endif | 746 | #endif |
747 | |||
748 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
749 | "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" | ||
750 | "\t-k\tprint sizes in kilobytes(default)\n" | ||
751 | #else | ||
752 | "\t-k\tprint sizes in kilobytes(compatability)" | ||
753 | #endif | ||
754 | |||
719 | #endif /* BB_FEATURE_TRIVIAL_HELP */ | 755 | #endif /* BB_FEATURE_TRIVIAL_HELP */ |
720 | ; | 756 | ; |
721 | #endif /* BB_LS */ | 757 | #endif /* BB_LS */ |
@@ -259,4 +259,11 @@ extern int sysinfo (struct sysinfo* info); | |||
259 | #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) | 259 | #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) |
260 | #endif | 260 | #endif |
261 | 261 | ||
262 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
263 | char *format(unsigned long val, unsigned long hr); | ||
264 | #define KILOBYTE 1024 | ||
265 | #define MEGABYTE (KILOBYTE*1024) | ||
266 | #define GIGABYTE (MEGABYTE*1024) | ||
267 | #endif | ||
268 | |||
262 | #endif /* _BB_INTERNAL_H_ */ | 269 | #endif /* _BB_INTERNAL_H_ */ |
diff --git a/coreutils/df.c b/coreutils/df.c index dc4849049..aa04682a7 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -28,6 +28,9 @@ | |||
28 | #include <sys/vfs.h> | 28 | #include <sys/vfs.h> |
29 | 29 | ||
30 | extern const char mtab_file[]; /* Defined in utility.c */ | 30 | extern const char mtab_file[]; /* Defined in utility.c */ |
31 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
32 | unsigned long disp_hr = KILOBYTE; | ||
33 | #endif | ||
31 | 34 | ||
32 | static int df(char *device, const char *mountPoint) | 35 | static int df(char *device, const char *mountPoint) |
33 | { | 36 | { |
@@ -42,19 +45,32 @@ static int df(char *device, const char *mountPoint) | |||
42 | 45 | ||
43 | if (s.f_blocks > 0) { | 46 | if (s.f_blocks > 0) { |
44 | blocks_used = s.f_blocks - s.f_bfree; | 47 | blocks_used = s.f_blocks - s.f_bfree; |
45 | blocks_percent_used = (long) | 48 | if(0 == blocks_used) |
46 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 49 | blocs_percent_used = 0; |
50 | else | ||
51 | blocks_percent_used = (long) | ||
52 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | ||
47 | if (strcmp(device, "/dev/root") == 0) { | 53 | if (strcmp(device, "/dev/root") == 0) { |
48 | /* Adjusts device to be the real root device, | 54 | /* Adjusts device to be the real root device, |
49 | * or leaves device alone if it can't find it */ | 55 | * or leaves device alone if it can't find it */ |
50 | find_real_root_device_name( device); | 56 | find_real_root_device_name( device); |
51 | } | 57 | } |
58 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
59 | printf("%-20s %9s", | ||
60 | device, | ||
61 | format((s.f_blocks * s.f_bsize), disp_hr)); | ||
62 | printf(" %9s", format((s.f_blocks - s.f_bfree) * s.f_bsize, disp_hr)); | ||
63 | printf(" %9s %3ld%% %s\n", | ||
64 | format(s.f_bavail * s.f_bsize, disp_hr), | ||
65 | blocks_percent_used, mountPoint); | ||
66 | #else | ||
52 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", | 67 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", |
53 | device, | 68 | device, |
54 | (long) (s.f_blocks * (s.f_bsize / 1024.0)), | 69 | (long) (s.f_blocks * (s.f_bsize / 1024.0)), |
55 | (long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)), | 70 | (long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)), |
56 | (long) (s.f_bavail * (s.f_bsize / 1024.0)), | 71 | (long) (s.f_bavail * (s.f_bsize / 1024.0)), |
57 | blocks_percent_used, mountPoint); | 72 | blocks_percent_used, mountPoint); |
73 | #endif | ||
58 | 74 | ||
59 | } | 75 | } |
60 | 76 | ||
@@ -64,24 +80,46 @@ static int df(char *device, const char *mountPoint) | |||
64 | extern int df_main(int argc, char **argv) | 80 | extern int df_main(int argc, char **argv) |
65 | { | 81 | { |
66 | int status = EXIT_SUCCESS; | 82 | int status = EXIT_SUCCESS; |
83 | int opt = 0; | ||
84 | int i = 0; | ||
85 | |||
86 | while ((opt = getopt(argc, argv, "?" | ||
87 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
88 | "hm" | ||
89 | #endif | ||
90 | "k" | ||
91 | )) > 0) | ||
92 | { | ||
93 | switch (opt) { | ||
94 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
95 | case 'h': disp_hr = 0; break; | ||
96 | case 'm': disp_hr = MEGABYTE; break; | ||
97 | case 'k': disp_hr = KILOBYTE; break; | ||
98 | #else | ||
99 | case 'k': break; | ||
100 | #endif | ||
101 | case '?': goto print_df_usage; break; | ||
102 | } | ||
103 | } | ||
67 | 104 | ||
68 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", | 105 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", |
69 | "1k-blocks", "Used", "Available", "Use%", "Mounted on"); | 106 | #ifdef BB_FEATURE_HUMAN_READABLE |
107 | (KILOBYTE == disp_hr) ? "1k-blocks" : " Size", | ||
108 | #else | ||
109 | "1k-blocks", | ||
110 | #endif | ||
111 | "Used", "Available", "Use%", "Mounted on"); | ||
70 | 112 | ||
71 | if (argc > 1) { | ||
72 | struct mntent *mountEntry; | ||
73 | 113 | ||
74 | if (**(argv + 1) == '-') { | 114 | if(optind < argc) { |
75 | usage(df_usage); | 115 | struct mntent *mountEntry; |
76 | } | 116 | for(i = optind; i < argc; i++) |
77 | while (argc > 1) { | 117 | { |
78 | if ((mountEntry = find_mount_point(argv[1], mtab_file)) == 0) { | 118 | if ((mountEntry = find_mount_point(argv[i], mtab_file)) == 0) { |
79 | error_msg("%s: can't find mount point.\n", argv[1]); | 119 | error_msg("%s: can't find mount point.\n", argv[i]); |
80 | status = EXIT_FAILURE; | 120 | status = EXIT_FAILURE; |
81 | } else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir)) | 121 | } else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir)) |
82 | status = EXIT_FAILURE; | 122 | status = EXIT_FAILURE; |
83 | argc--; | ||
84 | argv++; | ||
85 | } | 123 | } |
86 | } else { | 124 | } else { |
87 | FILE *mountTable; | 125 | FILE *mountTable; |
@@ -101,6 +139,10 @@ extern int df_main(int argc, char **argv) | |||
101 | } | 139 | } |
102 | 140 | ||
103 | return status; | 141 | return status; |
142 | |||
143 | print_df_usage: | ||
144 | usage(df_usage); | ||
145 | return(FALSE); | ||
104 | } | 146 | } |
105 | 147 | ||
106 | /* | 148 | /* |
diff --git a/coreutils/du.c b/coreutils/du.c index 8628732d8..56a7a9a0c 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -33,6 +33,10 @@ | |||
33 | #include <stdio.h> | 33 | #include <stdio.h> |
34 | #include <errno.h> | 34 | #include <errno.h> |
35 | 35 | ||
36 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
37 | unsigned long du_disp_hr = KILOBYTE; | ||
38 | #endif | ||
39 | |||
36 | typedef void (Display) (long, char *); | 40 | typedef void (Display) (long, char *); |
37 | 41 | ||
38 | static int du_depth = 0; | 42 | static int du_depth = 0; |
@@ -42,12 +46,17 @@ static Display *print; | |||
42 | 46 | ||
43 | static void print_normal(long size, char *filename) | 47 | static void print_normal(long size, char *filename) |
44 | { | 48 | { |
49 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
50 | printf("%s\t%s\n", format((size * KILOBYTE), du_disp_hr), filename); | ||
51 | #else | ||
45 | printf("%ld\t%s\n", size, filename); | 52 | printf("%ld\t%s\n", size, filename); |
53 | #endif | ||
46 | } | 54 | } |
47 | 55 | ||
48 | static void print_summary(long size, char *filename) | 56 | static void print_summary(long size, char *filename) |
49 | { | 57 | { |
50 | if (du_depth == 1) { | 58 | if (du_depth == 1) { |
59 | printf("summary\n"); | ||
51 | print_normal(size, filename); | 60 | print_normal(size, filename); |
52 | } | 61 | } |
53 | } | 62 | } |
@@ -132,7 +141,11 @@ int du_main(int argc, char **argv) | |||
132 | print = print_normal; | 141 | print = print_normal; |
133 | 142 | ||
134 | /* parse argv[] */ | 143 | /* parse argv[] */ |
135 | while ((c = getopt(argc, argv, "sl")) != EOF) { | 144 | while ((c = getopt(argc, argv, "sl" |
145 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
146 | "hm" | ||
147 | #endif | ||
148 | "k")) != EOF) { | ||
136 | switch (c) { | 149 | switch (c) { |
137 | case 's': | 150 | case 's': |
138 | print = print_summary; | 151 | print = print_summary; |
@@ -140,6 +153,13 @@ int du_main(int argc, char **argv) | |||
140 | case 'l': | 153 | case 'l': |
141 | count_hardlinks = 1; | 154 | count_hardlinks = 1; |
142 | break; | 155 | break; |
156 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
157 | case 'h': du_disp_hr = 0; break; | ||
158 | case 'm': du_disp_hr = MEGABYTE; break; | ||
159 | case 'k': du_disp_hr = KILOBYTE; break; | ||
160 | #else | ||
161 | case 'k': break; | ||
162 | #endif | ||
143 | default: | 163 | default: |
144 | usage(du_usage); | 164 | usage(du_usage); |
145 | } | 165 | } |
@@ -155,7 +175,7 @@ int du_main(int argc, char **argv) | |||
155 | for (i=optind; i < argc; i++) { | 175 | for (i=optind; i < argc; i++) { |
156 | if ((sum = du(argv[i])) == 0) | 176 | if ((sum = du(argv[i])) == 0) |
157 | status = EXIT_FAILURE; | 177 | status = EXIT_FAILURE; |
158 | if (is_directory(argv[i], FALSE, NULL)==FALSE) { | 178 | if(is_directory(argv[i], FALSE, NULL)==FALSE) { |
159 | print_normal(sum, argv[i]); | 179 | print_normal(sum, argv[i]); |
160 | } | 180 | } |
161 | reset_ino_dev_hashtable(); | 181 | reset_ino_dev_hashtable(); |
@@ -165,7 +185,7 @@ int du_main(int argc, char **argv) | |||
165 | return status; | 185 | return status; |
166 | } | 186 | } |
167 | 187 | ||
168 | /* $Id: du.c,v 1.33 2001/01/18 02:57:08 kraai Exp $ */ | 188 | /* $Id: du.c,v 1.34 2001/01/22 22:35:38 rjune Exp $ */ |
169 | /* | 189 | /* |
170 | Local Variables: | 190 | Local Variables: |
171 | c-file-style: "linux" | 191 | c-file-style: "linux" |
diff --git a/coreutils/ls.c b/coreutils/ls.c index fa3e5424d..754a6d450 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -176,6 +176,10 @@ static unsigned short tabstops = 8; | |||
176 | 176 | ||
177 | static int status = EXIT_SUCCESS; | 177 | static int status = EXIT_SUCCESS; |
178 | 178 | ||
179 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
180 | unsigned long ls_disp_hr = KILOBYTE; | ||
181 | #endif | ||
182 | |||
179 | static int my_stat(struct dnode *cur) | 183 | static int my_stat(struct dnode *cur) |
180 | { | 184 | { |
181 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 185 | #ifdef BB_FEATURE_LS_FOLLOWLINKS |
@@ -583,11 +587,15 @@ int list_single(struct dnode *dn) | |||
583 | column += 8; | 587 | column += 8; |
584 | break; | 588 | break; |
585 | case LIST_BLOCKS: | 589 | case LIST_BLOCKS: |
590 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
591 | fprintf(stdout, "%5s ", format(dn->dstat.st_size, ls_disp_hr)); | ||
592 | #else | ||
586 | #if _FILE_OFFSET_BITS == 64 | 593 | #if _FILE_OFFSET_BITS == 64 |
587 | printf("%4lld ", dn->dstat.st_blocks>>1); | 594 | printf("%4lld ", dn->dstat.st_blocks>>1); |
588 | #else | 595 | #else |
589 | printf("%4ld ", dn->dstat.st_blocks>>1); | 596 | printf("%4ld ", dn->dstat.st_blocks>>1); |
590 | #endif | 597 | #endif |
598 | #endif | ||
591 | column += 5; | 599 | column += 5; |
592 | break; | 600 | break; |
593 | case LIST_MODEBITS: | 601 | case LIST_MODEBITS: |
@@ -622,11 +630,15 @@ int list_single(struct dnode *dn) | |||
622 | if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { | 630 | if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { |
623 | printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev)); | 631 | printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev)); |
624 | } else { | 632 | } else { |
633 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
634 | fprintf(stdout, "%9s ", format(dn->dstat.st_size, ls_disp_hr)); | ||
635 | #else | ||
625 | #if _FILE_OFFSET_BITS == 64 | 636 | #if _FILE_OFFSET_BITS == 64 |
626 | printf("%9lld ", dn->dstat.st_size); | 637 | printf("%9lld ", dn->dstat.st_size); |
627 | #else | 638 | #else |
628 | printf("%9ld ", dn->dstat.st_size); | 639 | printf("%9ld ", dn->dstat.st_size); |
629 | #endif | 640 | #endif |
641 | #endif | ||
630 | } | 642 | } |
631 | column += 10; | 643 | column += 10; |
632 | break; | 644 | break; |
@@ -724,7 +736,10 @@ extern int ls_main(int argc, char **argv) | |||
724 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 736 | #ifdef BB_FEATURE_LS_FOLLOWLINKS |
725 | "L" | 737 | "L" |
726 | #endif | 738 | #endif |
727 | )) > 0) { | 739 | #ifdef BB_FEATURE_HUMAN_READABLE |
740 | "h" | ||
741 | #endif | ||
742 | "k")) > 0) { | ||
728 | switch (opt) { | 743 | switch (opt) { |
729 | case '1': style_fmt = STYLE_SINGLE; break; | 744 | case '1': style_fmt = STYLE_SINGLE; break; |
730 | case 'A': disp_opts |= DISP_HIDDEN; break; | 745 | case 'A': disp_opts |= DISP_HIDDEN; break; |
@@ -733,7 +748,13 @@ extern int ls_main(int argc, char **argv) | |||
733 | case 'd': disp_opts |= DISP_NOLIST; break; | 748 | case 'd': disp_opts |= DISP_NOLIST; break; |
734 | case 'g': /* ignore -- for ftp servers */ break; | 749 | case 'g': /* ignore -- for ftp servers */ break; |
735 | case 'i': list_fmt |= LIST_INO; break; | 750 | case 'i': list_fmt |= LIST_INO; break; |
736 | case 'l': style_fmt = STYLE_LONG; list_fmt |= LIST_LONG; break; | 751 | case 'l': |
752 | style_fmt = STYLE_LONG; | ||
753 | list_fmt |= LIST_LONG; | ||
754 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
755 | ls_disp_hr = 1; | ||
756 | #endif | ||
757 | break; | ||
737 | case 'n': list_fmt |= LIST_ID_NUMERIC; break; | 758 | case 'n': list_fmt |= LIST_ID_NUMERIC; break; |
738 | case 's': list_fmt |= LIST_BLOCKS; break; | 759 | case 's': list_fmt |= LIST_BLOCKS; break; |
739 | case 'x': disp_opts = DISP_ROWS; break; | 760 | case 'x': disp_opts = DISP_ROWS; break; |
@@ -777,6 +798,12 @@ extern int ls_main(int argc, char **argv) | |||
777 | case 'T': tabstops= atoi(optarg); break; | 798 | case 'T': tabstops= atoi(optarg); break; |
778 | case 'w': terminal_width= atoi(optarg); break; | 799 | case 'w': terminal_width= atoi(optarg); break; |
779 | #endif | 800 | #endif |
801 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
802 | case 'h': ls_disp_hr = 0; break; | ||
803 | case 'k': ls_disp_hr = KILOBYTE; break; | ||
804 | #else | ||
805 | case 'k': break; | ||
806 | #endif | ||
780 | default: | 807 | default: |
781 | goto print_usage_message; | 808 | goto print_usage_message; |
782 | } | 809 | } |
@@ -28,6 +28,9 @@ | |||
28 | #include <sys/vfs.h> | 28 | #include <sys/vfs.h> |
29 | 29 | ||
30 | extern const char mtab_file[]; /* Defined in utility.c */ | 30 | extern const char mtab_file[]; /* Defined in utility.c */ |
31 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
32 | unsigned long disp_hr = KILOBYTE; | ||
33 | #endif | ||
31 | 34 | ||
32 | static int df(char *device, const char *mountPoint) | 35 | static int df(char *device, const char *mountPoint) |
33 | { | 36 | { |
@@ -42,19 +45,32 @@ static int df(char *device, const char *mountPoint) | |||
42 | 45 | ||
43 | if (s.f_blocks > 0) { | 46 | if (s.f_blocks > 0) { |
44 | blocks_used = s.f_blocks - s.f_bfree; | 47 | blocks_used = s.f_blocks - s.f_bfree; |
45 | blocks_percent_used = (long) | 48 | if(0 == blocks_used) |
46 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 49 | blocs_percent_used = 0; |
50 | else | ||
51 | blocks_percent_used = (long) | ||
52 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | ||
47 | if (strcmp(device, "/dev/root") == 0) { | 53 | if (strcmp(device, "/dev/root") == 0) { |
48 | /* Adjusts device to be the real root device, | 54 | /* Adjusts device to be the real root device, |
49 | * or leaves device alone if it can't find it */ | 55 | * or leaves device alone if it can't find it */ |
50 | find_real_root_device_name( device); | 56 | find_real_root_device_name( device); |
51 | } | 57 | } |
58 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
59 | printf("%-20s %9s", | ||
60 | device, | ||
61 | format((s.f_blocks * s.f_bsize), disp_hr)); | ||
62 | printf(" %9s", format((s.f_blocks - s.f_bfree) * s.f_bsize, disp_hr)); | ||
63 | printf(" %9s %3ld%% %s\n", | ||
64 | format(s.f_bavail * s.f_bsize, disp_hr), | ||
65 | blocks_percent_used, mountPoint); | ||
66 | #else | ||
52 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", | 67 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", |
53 | device, | 68 | device, |
54 | (long) (s.f_blocks * (s.f_bsize / 1024.0)), | 69 | (long) (s.f_blocks * (s.f_bsize / 1024.0)), |
55 | (long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)), | 70 | (long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)), |
56 | (long) (s.f_bavail * (s.f_bsize / 1024.0)), | 71 | (long) (s.f_bavail * (s.f_bsize / 1024.0)), |
57 | blocks_percent_used, mountPoint); | 72 | blocks_percent_used, mountPoint); |
73 | #endif | ||
58 | 74 | ||
59 | } | 75 | } |
60 | 76 | ||
@@ -64,24 +80,46 @@ static int df(char *device, const char *mountPoint) | |||
64 | extern int df_main(int argc, char **argv) | 80 | extern int df_main(int argc, char **argv) |
65 | { | 81 | { |
66 | int status = EXIT_SUCCESS; | 82 | int status = EXIT_SUCCESS; |
83 | int opt = 0; | ||
84 | int i = 0; | ||
85 | |||
86 | while ((opt = getopt(argc, argv, "?" | ||
87 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
88 | "hm" | ||
89 | #endif | ||
90 | "k" | ||
91 | )) > 0) | ||
92 | { | ||
93 | switch (opt) { | ||
94 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
95 | case 'h': disp_hr = 0; break; | ||
96 | case 'm': disp_hr = MEGABYTE; break; | ||
97 | case 'k': disp_hr = KILOBYTE; break; | ||
98 | #else | ||
99 | case 'k': break; | ||
100 | #endif | ||
101 | case '?': goto print_df_usage; break; | ||
102 | } | ||
103 | } | ||
67 | 104 | ||
68 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", | 105 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", |
69 | "1k-blocks", "Used", "Available", "Use%", "Mounted on"); | 106 | #ifdef BB_FEATURE_HUMAN_READABLE |
107 | (KILOBYTE == disp_hr) ? "1k-blocks" : " Size", | ||
108 | #else | ||
109 | "1k-blocks", | ||
110 | #endif | ||
111 | "Used", "Available", "Use%", "Mounted on"); | ||
70 | 112 | ||
71 | if (argc > 1) { | ||
72 | struct mntent *mountEntry; | ||
73 | 113 | ||
74 | if (**(argv + 1) == '-') { | 114 | if(optind < argc) { |
75 | usage(df_usage); | 115 | struct mntent *mountEntry; |
76 | } | 116 | for(i = optind; i < argc; i++) |
77 | while (argc > 1) { | 117 | { |
78 | if ((mountEntry = find_mount_point(argv[1], mtab_file)) == 0) { | 118 | if ((mountEntry = find_mount_point(argv[i], mtab_file)) == 0) { |
79 | error_msg("%s: can't find mount point.\n", argv[1]); | 119 | error_msg("%s: can't find mount point.\n", argv[i]); |
80 | status = EXIT_FAILURE; | 120 | status = EXIT_FAILURE; |
81 | } else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir)) | 121 | } else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir)) |
82 | status = EXIT_FAILURE; | 122 | status = EXIT_FAILURE; |
83 | argc--; | ||
84 | argv++; | ||
85 | } | 123 | } |
86 | } else { | 124 | } else { |
87 | FILE *mountTable; | 125 | FILE *mountTable; |
@@ -101,6 +139,10 @@ extern int df_main(int argc, char **argv) | |||
101 | } | 139 | } |
102 | 140 | ||
103 | return status; | 141 | return status; |
142 | |||
143 | print_df_usage: | ||
144 | usage(df_usage); | ||
145 | return(FALSE); | ||
104 | } | 146 | } |
105 | 147 | ||
106 | /* | 148 | /* |
@@ -33,6 +33,10 @@ | |||
33 | #include <stdio.h> | 33 | #include <stdio.h> |
34 | #include <errno.h> | 34 | #include <errno.h> |
35 | 35 | ||
36 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
37 | unsigned long du_disp_hr = KILOBYTE; | ||
38 | #endif | ||
39 | |||
36 | typedef void (Display) (long, char *); | 40 | typedef void (Display) (long, char *); |
37 | 41 | ||
38 | static int du_depth = 0; | 42 | static int du_depth = 0; |
@@ -42,12 +46,17 @@ static Display *print; | |||
42 | 46 | ||
43 | static void print_normal(long size, char *filename) | 47 | static void print_normal(long size, char *filename) |
44 | { | 48 | { |
49 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
50 | printf("%s\t%s\n", format((size * KILOBYTE), du_disp_hr), filename); | ||
51 | #else | ||
45 | printf("%ld\t%s\n", size, filename); | 52 | printf("%ld\t%s\n", size, filename); |
53 | #endif | ||
46 | } | 54 | } |
47 | 55 | ||
48 | static void print_summary(long size, char *filename) | 56 | static void print_summary(long size, char *filename) |
49 | { | 57 | { |
50 | if (du_depth == 1) { | 58 | if (du_depth == 1) { |
59 | printf("summary\n"); | ||
51 | print_normal(size, filename); | 60 | print_normal(size, filename); |
52 | } | 61 | } |
53 | } | 62 | } |
@@ -132,7 +141,11 @@ int du_main(int argc, char **argv) | |||
132 | print = print_normal; | 141 | print = print_normal; |
133 | 142 | ||
134 | /* parse argv[] */ | 143 | /* parse argv[] */ |
135 | while ((c = getopt(argc, argv, "sl")) != EOF) { | 144 | while ((c = getopt(argc, argv, "sl" |
145 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
146 | "hm" | ||
147 | #endif | ||
148 | "k")) != EOF) { | ||
136 | switch (c) { | 149 | switch (c) { |
137 | case 's': | 150 | case 's': |
138 | print = print_summary; | 151 | print = print_summary; |
@@ -140,6 +153,13 @@ int du_main(int argc, char **argv) | |||
140 | case 'l': | 153 | case 'l': |
141 | count_hardlinks = 1; | 154 | count_hardlinks = 1; |
142 | break; | 155 | break; |
156 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
157 | case 'h': du_disp_hr = 0; break; | ||
158 | case 'm': du_disp_hr = MEGABYTE; break; | ||
159 | case 'k': du_disp_hr = KILOBYTE; break; | ||
160 | #else | ||
161 | case 'k': break; | ||
162 | #endif | ||
143 | default: | 163 | default: |
144 | usage(du_usage); | 164 | usage(du_usage); |
145 | } | 165 | } |
@@ -155,7 +175,7 @@ int du_main(int argc, char **argv) | |||
155 | for (i=optind; i < argc; i++) { | 175 | for (i=optind; i < argc; i++) { |
156 | if ((sum = du(argv[i])) == 0) | 176 | if ((sum = du(argv[i])) == 0) |
157 | status = EXIT_FAILURE; | 177 | status = EXIT_FAILURE; |
158 | if (is_directory(argv[i], FALSE, NULL)==FALSE) { | 178 | if(is_directory(argv[i], FALSE, NULL)==FALSE) { |
159 | print_normal(sum, argv[i]); | 179 | print_normal(sum, argv[i]); |
160 | } | 180 | } |
161 | reset_ino_dev_hashtable(); | 181 | reset_ino_dev_hashtable(); |
@@ -165,7 +185,7 @@ int du_main(int argc, char **argv) | |||
165 | return status; | 185 | return status; |
166 | } | 186 | } |
167 | 187 | ||
168 | /* $Id: du.c,v 1.33 2001/01/18 02:57:08 kraai Exp $ */ | 188 | /* $Id: du.c,v 1.34 2001/01/22 22:35:38 rjune Exp $ */ |
169 | /* | 189 | /* |
170 | Local Variables: | 190 | Local Variables: |
171 | c-file-style: "linux" | 191 | c-file-style: "linux" |
diff --git a/include/busybox.h b/include/busybox.h index a89ac3694..018c636cf 100644 --- a/include/busybox.h +++ b/include/busybox.h | |||
@@ -259,4 +259,11 @@ extern int sysinfo (struct sysinfo* info); | |||
259 | #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) | 259 | #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) |
260 | #endif | 260 | #endif |
261 | 261 | ||
262 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
263 | char *format(unsigned long val, unsigned long hr); | ||
264 | #define KILOBYTE 1024 | ||
265 | #define MEGABYTE (KILOBYTE*1024) | ||
266 | #define GIGABYTE (MEGABYTE*1024) | ||
267 | #endif | ||
268 | |||
262 | #endif /* _BB_INTERNAL_H_ */ | 269 | #endif /* _BB_INTERNAL_H_ */ |
@@ -176,6 +176,10 @@ static unsigned short tabstops = 8; | |||
176 | 176 | ||
177 | static int status = EXIT_SUCCESS; | 177 | static int status = EXIT_SUCCESS; |
178 | 178 | ||
179 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
180 | unsigned long ls_disp_hr = KILOBYTE; | ||
181 | #endif | ||
182 | |||
179 | static int my_stat(struct dnode *cur) | 183 | static int my_stat(struct dnode *cur) |
180 | { | 184 | { |
181 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 185 | #ifdef BB_FEATURE_LS_FOLLOWLINKS |
@@ -583,11 +587,15 @@ int list_single(struct dnode *dn) | |||
583 | column += 8; | 587 | column += 8; |
584 | break; | 588 | break; |
585 | case LIST_BLOCKS: | 589 | case LIST_BLOCKS: |
590 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
591 | fprintf(stdout, "%5s ", format(dn->dstat.st_size, ls_disp_hr)); | ||
592 | #else | ||
586 | #if _FILE_OFFSET_BITS == 64 | 593 | #if _FILE_OFFSET_BITS == 64 |
587 | printf("%4lld ", dn->dstat.st_blocks>>1); | 594 | printf("%4lld ", dn->dstat.st_blocks>>1); |
588 | #else | 595 | #else |
589 | printf("%4ld ", dn->dstat.st_blocks>>1); | 596 | printf("%4ld ", dn->dstat.st_blocks>>1); |
590 | #endif | 597 | #endif |
598 | #endif | ||
591 | column += 5; | 599 | column += 5; |
592 | break; | 600 | break; |
593 | case LIST_MODEBITS: | 601 | case LIST_MODEBITS: |
@@ -622,11 +630,15 @@ int list_single(struct dnode *dn) | |||
622 | if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { | 630 | if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { |
623 | printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev)); | 631 | printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev)); |
624 | } else { | 632 | } else { |
633 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
634 | fprintf(stdout, "%9s ", format(dn->dstat.st_size, ls_disp_hr)); | ||
635 | #else | ||
625 | #if _FILE_OFFSET_BITS == 64 | 636 | #if _FILE_OFFSET_BITS == 64 |
626 | printf("%9lld ", dn->dstat.st_size); | 637 | printf("%9lld ", dn->dstat.st_size); |
627 | #else | 638 | #else |
628 | printf("%9ld ", dn->dstat.st_size); | 639 | printf("%9ld ", dn->dstat.st_size); |
629 | #endif | 640 | #endif |
641 | #endif | ||
630 | } | 642 | } |
631 | column += 10; | 643 | column += 10; |
632 | break; | 644 | break; |
@@ -724,7 +736,10 @@ extern int ls_main(int argc, char **argv) | |||
724 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 736 | #ifdef BB_FEATURE_LS_FOLLOWLINKS |
725 | "L" | 737 | "L" |
726 | #endif | 738 | #endif |
727 | )) > 0) { | 739 | #ifdef BB_FEATURE_HUMAN_READABLE |
740 | "h" | ||
741 | #endif | ||
742 | "k")) > 0) { | ||
728 | switch (opt) { | 743 | switch (opt) { |
729 | case '1': style_fmt = STYLE_SINGLE; break; | 744 | case '1': style_fmt = STYLE_SINGLE; break; |
730 | case 'A': disp_opts |= DISP_HIDDEN; break; | 745 | case 'A': disp_opts |= DISP_HIDDEN; break; |
@@ -733,7 +748,13 @@ extern int ls_main(int argc, char **argv) | |||
733 | case 'd': disp_opts |= DISP_NOLIST; break; | 748 | case 'd': disp_opts |= DISP_NOLIST; break; |
734 | case 'g': /* ignore -- for ftp servers */ break; | 749 | case 'g': /* ignore -- for ftp servers */ break; |
735 | case 'i': list_fmt |= LIST_INO; break; | 750 | case 'i': list_fmt |= LIST_INO; break; |
736 | case 'l': style_fmt = STYLE_LONG; list_fmt |= LIST_LONG; break; | 751 | case 'l': |
752 | style_fmt = STYLE_LONG; | ||
753 | list_fmt |= LIST_LONG; | ||
754 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
755 | ls_disp_hr = 1; | ||
756 | #endif | ||
757 | break; | ||
737 | case 'n': list_fmt |= LIST_ID_NUMERIC; break; | 758 | case 'n': list_fmt |= LIST_ID_NUMERIC; break; |
738 | case 's': list_fmt |= LIST_BLOCKS; break; | 759 | case 's': list_fmt |= LIST_BLOCKS; break; |
739 | case 'x': disp_opts = DISP_ROWS; break; | 760 | case 'x': disp_opts = DISP_ROWS; break; |
@@ -777,6 +798,12 @@ extern int ls_main(int argc, char **argv) | |||
777 | case 'T': tabstops= atoi(optarg); break; | 798 | case 'T': tabstops= atoi(optarg); break; |
778 | case 'w': terminal_width= atoi(optarg); break; | 799 | case 'w': terminal_width= atoi(optarg); break; |
779 | #endif | 800 | #endif |
801 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
802 | case 'h': ls_disp_hr = 0; break; | ||
803 | case 'k': ls_disp_hr = KILOBYTE; break; | ||
804 | #else | ||
805 | case 'k': break; | ||
806 | #endif | ||
780 | default: | 807 | default: |
781 | goto print_usage_message; | 808 | goto print_usage_message; |
782 | } | 809 | } |
@@ -190,9 +190,22 @@ const char deallocvt_usage[] = | |||
190 | 190 | ||
191 | #if defined BB_DF | 191 | #if defined BB_DF |
192 | const char df_usage[] = | 192 | const char df_usage[] = |
193 | "df [filesystem ...]" | 193 | "df [-?" |
194 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
195 | "hm" | ||
196 | #endif | ||
197 | "k] [filesystem ...]\n" | ||
194 | #ifndef BB_FEATURE_TRIVIAL_HELP | 198 | #ifndef BB_FEATURE_TRIVIAL_HELP |
195 | "\n\nPrint the filesystem space used and space available." | 199 | "\n\nPrint the filesystem space used and space available." |
200 | "Options:\n" | ||
201 | "\t-?\tshow usage information\n" | ||
202 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
203 | "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" | ||
204 | "\t-m\tprint sizes in megabytes\n" | ||
205 | "\t-k\tprint sizes in kilobytes(default)\n" | ||
206 | #else | ||
207 | "\t-k\tprint sizes in kilobytes(compatability)\n" | ||
208 | #endif | ||
196 | #endif | 209 | #endif |
197 | ; | 210 | ; |
198 | #endif | 211 | #endif |
@@ -244,13 +257,25 @@ const char dpkg_deb_usage[] = | |||
244 | 257 | ||
245 | #if defined BB_DU | 258 | #if defined BB_DU |
246 | const char du_usage[] = | 259 | const char du_usage[] = |
247 | "du [OPTION]... [FILE]..." | 260 | "du [-?ls" |
261 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
262 | "hm" | ||
263 | #endif | ||
264 | "k] [FILE]...\n" | ||
248 | #ifndef BB_FEATURE_TRIVIAL_HELP | 265 | #ifndef BB_FEATURE_TRIVIAL_HELP |
249 | "\n\nSummarizes disk space used for each FILE and/or directory.\n" | 266 | "\n\nSummarizes disk space used for each FILE and/or directory.\n" |
250 | "Disk space is printed in units of 1024 bytes.\n\n" | 267 | "Disk space is printed in units of 1024 bytes.\n\n" |
251 | "Options:\n" | 268 | "Options:\n" |
269 | "\t-?\tshow usage information\n" | ||
252 | "\t-l\tcount sizes many times if hard linked\n" | 270 | "\t-l\tcount sizes many times if hard linked\n" |
253 | "\t-s\tdisplay only a total for each argument" | 271 | "\t-s\tdisplay only a total for each argument" |
272 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
273 | "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" | ||
274 | "\t-m\tprint sizes in megabytes\n" | ||
275 | "\t-k\tprint sizes in kilobytes(default)\n" | ||
276 | #else | ||
277 | "\t-k\tprint sizes in kilobytes(compatability)\n" | ||
278 | #endif | ||
254 | #endif | 279 | #endif |
255 | ; | 280 | ; |
256 | #endif | 281 | #endif |
@@ -661,7 +686,10 @@ const char ls_usage[] = | |||
661 | #ifdef BB_FEATURE_LS_SORTFILES | 686 | #ifdef BB_FEATURE_LS_SORTFILES |
662 | "X" | 687 | "X" |
663 | #endif | 688 | #endif |
664 | "] [filenames...]" | 689 | #ifdef BB_FEATURE_HUMAN_READABLE |
690 | "h" | ||
691 | #endif | ||
692 | "k] [filenames...]\n" | ||
665 | #ifndef BB_FEATURE_TRIVIAL_HELP | 693 | #ifndef BB_FEATURE_TRIVIAL_HELP |
666 | "\n\nList directory contents\n\n" | 694 | "\n\nList directory contents\n\n" |
667 | "Options:\n" | 695 | "Options:\n" |
@@ -716,6 +744,14 @@ const char ls_usage[] = | |||
716 | #ifdef BB_FEATURE_LS_SORTFILES | 744 | #ifdef BB_FEATURE_LS_SORTFILES |
717 | "\t-X\tsort the listing by extension\n" | 745 | "\t-X\tsort the listing by extension\n" |
718 | #endif | 746 | #endif |
747 | |||
748 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
749 | "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" | ||
750 | "\t-k\tprint sizes in kilobytes(default)\n" | ||
751 | #else | ||
752 | "\t-k\tprint sizes in kilobytes(compatability)" | ||
753 | #endif | ||
754 | |||
719 | #endif /* BB_FEATURE_TRIVIAL_HELP */ | 755 | #endif /* BB_FEATURE_TRIVIAL_HELP */ |
720 | ; | 756 | ; |
721 | #endif /* BB_LS */ | 757 | #endif /* BB_LS */ |
@@ -1770,6 +1770,27 @@ ssize_t safe_read(int fd, void *buf, size_t count) | |||
1770 | } | 1770 | } |
1771 | #endif | 1771 | #endif |
1772 | 1772 | ||
1773 | #ifdef BB_FEATURE_HUMAN_READABLE | ||
1774 | char *format(unsigned long val, unsigned long hr) | ||
1775 | { | ||
1776 | static char str[10] = "\0"; | ||
1777 | |||
1778 | if(val == 0) | ||
1779 | return("0"); | ||
1780 | if(hr) | ||
1781 | snprintf(str, 9, "%ld", val/hr); | ||
1782 | else if(val >= GIGABYTE) | ||
1783 | snprintf(str, 9, "%.1LfG", ((long double)(val)/GIGABYTE)); | ||
1784 | else if(val >= MEGABYTE) | ||
1785 | snprintf(str, 9, "%.1LfM", ((long double)(val)/MEGABYTE)); | ||
1786 | else if(val >= KILOBYTE) | ||
1787 | snprintf(str, 9, "%.1Lfk", ((long double)(val)/KILOBYTE)); | ||
1788 | else | ||
1789 | snprintf(str, 9, "%ld", (val)); | ||
1790 | return(str); | ||
1791 | } | ||
1792 | #endif | ||
1793 | |||
1773 | /* END CODE */ | 1794 | /* END CODE */ |
1774 | /* | 1795 | /* |
1775 | Local Variables: | 1796 | Local Variables: |