diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-09-06 12:53:14 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-09-06 12:53:14 +0200 |
commit | a407cf74cc43c3cc26168e259cee469a4787a76c (patch) | |
tree | 2306029e1ea7b957825b55e3728d23c886da58dd | |
parent | d6ae4fb446daedfe3073d67be655942e9fa7eb18 (diff) | |
download | busybox-w32-a407cf74cc43c3cc26168e259cee469a4787a76c.tar.gz busybox-w32-a407cf74cc43c3cc26168e259cee469a4787a76c.tar.bz2 busybox-w32-a407cf74cc43c3cc26168e259cee469a4787a76c.zip |
Make smart_ulltoa return pointer to end (allows for code shink in callers)
function old new delta
smart_ulltoa5 405 408 +3
smart_ulltoa4 273 276 +3
list_table 1113 1114 +1
scale 36 34 -2
put_lu 55 53 -2
ulltoa6_and_space 19 14 -5
powertop_main 1470 1461 -9
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/human_readable.c | 6 | ||||
-rw-r--r-- | procps/nmeter.c | 3 | ||||
-rw-r--r-- | procps/powertop.c | 3 | ||||
-rw-r--r-- | procps/ps.c | 9 | ||||
-rw-r--r-- | procps/top.c | 3 | ||||
-rw-r--r-- | util-linux/fdisk_gpt.c | 6 |
7 files changed, 14 insertions, 20 deletions
diff --git a/include/libbb.h b/include/libbb.h index 6b95dc0ec..1315e5f8f 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -815,8 +815,8 @@ char *itoa(int n) FAST_FUNC; | |||
815 | char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; | 815 | char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; |
816 | char *itoa_to_buf(int n, char *buf, unsigned buflen) FAST_FUNC; | 816 | char *itoa_to_buf(int n, char *buf, unsigned buflen) FAST_FUNC; |
817 | /* Intelligent formatters of bignums */ | 817 | /* Intelligent formatters of bignums */ |
818 | void smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC; | 818 | char *smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC; |
819 | void smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC; | 819 | char *smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC; |
820 | /* If block_size == 0, display size without fractional part, | 820 | /* If block_size == 0, display size without fractional part, |
821 | * else display (size * block_size) with one decimal digit. | 821 | * else display (size * block_size) with one decimal digit. |
822 | * If display_unit == 0, show value no bigger than 1024 with suffix (K,M,G...), | 822 | * If display_unit == 0, show value no bigger than 1024 with suffix (K,M,G...), |
diff --git a/libbb/human_readable.c b/libbb/human_readable.c index 8b22b0cb5..0b2eb777e 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c | |||
@@ -94,7 +94,7 @@ const char* FAST_FUNC make_human_readable_str(unsigned long long val, | |||
94 | 94 | ||
95 | /* Convert unsigned long long value into compact 5-char representation. | 95 | /* Convert unsigned long long value into compact 5-char representation. |
96 | * String is not terminated (buf[5] is untouched) */ | 96 | * String is not terminated (buf[5] is untouched) */ |
97 | void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) | 97 | char* FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) |
98 | { | 98 | { |
99 | const char *fmt; | 99 | const char *fmt; |
100 | char c; | 100 | char c; |
@@ -145,12 +145,13 @@ void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *sca | |||
145 | buf[3] = "0123456789"[v]; | 145 | buf[3] = "0123456789"[v]; |
146 | buf[4] = scale[idx]; /* typically scale = " kmgt..." */ | 146 | buf[4] = scale[idx]; /* typically scale = " kmgt..." */ |
147 | } | 147 | } |
148 | return buf + 5; | ||
148 | } | 149 | } |
149 | 150 | ||
150 | /* Convert unsigned long long value into compact 4-char | 151 | /* Convert unsigned long long value into compact 4-char |
151 | * representation. Examples: "1234", "1.2k", " 27M", "123T" | 152 | * representation. Examples: "1234", "1.2k", " 27M", "123T" |
152 | * String is not terminated (buf[4] is untouched) */ | 153 | * String is not terminated (buf[4] is untouched) */ |
153 | void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) | 154 | char* FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) |
154 | { | 155 | { |
155 | const char *fmt; | 156 | const char *fmt; |
156 | char c; | 157 | char c; |
@@ -194,4 +195,5 @@ void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *sca | |||
194 | buf[2] = "0123456789"[v]; | 195 | buf[2] = "0123456789"[v]; |
195 | buf[3] = scale[idx]; /* typically scale = " kmgt..." */ | 196 | buf[3] = scale[idx]; /* typically scale = " kmgt..." */ |
196 | } | 197 | } |
198 | return buf + 4; | ||
197 | } | 199 | } |
diff --git a/procps/nmeter.c b/procps/nmeter.c index 6a3b32743..5d5b83b8d 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c | |||
@@ -333,8 +333,7 @@ static void scale(ullong ul) | |||
333 | char buf[5]; | 333 | char buf[5]; |
334 | 334 | ||
335 | /* see http://en.wikipedia.org/wiki/Tera */ | 335 | /* see http://en.wikipedia.org/wiki/Tera */ |
336 | smart_ulltoa4(ul, buf, " kmgtpezy"); | 336 | smart_ulltoa4(ul, buf, " kmgtpezy")[0] = '\0'; |
337 | buf[4] = '\0'; | ||
338 | put(buf); | 337 | put(buf); |
339 | } | 338 | } |
340 | 339 | ||
diff --git a/procps/powertop.c b/procps/powertop.c index 71988a295..e3c29d1c3 100644 --- a/procps/powertop.c +++ b/procps/powertop.c | |||
@@ -627,7 +627,6 @@ static void show_timerstats(void) | |||
627 | int i, n = 0; | 627 | int i, n = 0; |
628 | char strbuf6[6]; | 628 | char strbuf6[6]; |
629 | 629 | ||
630 | strbuf6[5] = '\0'; | ||
631 | puts("\nTop causes for wakeups:"); | 630 | puts("\nTop causes for wakeups:"); |
632 | for (i = 0; i < G.lines_cnt; i++) { | 631 | for (i = 0; i < G.lines_cnt; i++) { |
633 | if ((G.lines[i].count > 0 /*|| G.lines[i].disk_count > 0*/) | 632 | if ((G.lines[i].count > 0 /*|| G.lines[i].disk_count > 0*/) |
@@ -639,7 +638,7 @@ static void show_timerstats(void) | |||
639 | /*char c = ' '; | 638 | /*char c = ' '; |
640 | if (G.lines[i].disk_count) | 639 | if (G.lines[i].disk_count) |
641 | c = 'D';*/ | 640 | c = 'D';*/ |
642 | smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY"); | 641 | smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY")[0] = '\0'; |
643 | printf(/*" %5.1f%% (%s)%c %s\n"*/ | 642 | printf(/*" %5.1f%% (%s)%c %s\n"*/ |
644 | " %5.1f%% (%s) %s\n", | 643 | " %5.1f%% (%s) %s\n", |
645 | G.lines[i].count * 100.0 / G.lines_cumulative_count, | 644 | G.lines[i].count * 100.0 / G.lines_cumulative_count, |
diff --git a/procps/ps.c b/procps/ps.c index 89cadad00..c65fa012a 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -299,8 +299,7 @@ static void put_lu(char *buf, int size, unsigned long u) | |||
299 | char buf4[5]; | 299 | char buf4[5]; |
300 | 300 | ||
301 | /* see http://en.wikipedia.org/wiki/Tera */ | 301 | /* see http://en.wikipedia.org/wiki/Tera */ |
302 | smart_ulltoa4(u, buf4, " mgtpezy"); | 302 | smart_ulltoa4(u, buf4, " mgtpezy")[0] = '\0'; |
303 | buf4[4] = '\0'; | ||
304 | sprintf(buf, "%.*s", size, buf4); | 303 | sprintf(buf, "%.*s", size, buf4); |
305 | } | 304 | } |
306 | 305 | ||
@@ -740,8 +739,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
740 | #endif | 739 | #endif |
741 | { | 740 | { |
742 | char buf6[6]; | 741 | char buf6[6]; |
743 | smart_ulltoa5(p->vsz, buf6, " mgtpezy"); | 742 | smart_ulltoa5(p->vsz, buf6, " mgtpezy")[0] = '\0'; |
744 | buf6[5] = '\0'; | ||
745 | #if ENABLE_FEATURE_PS_LONG | 743 | #if ENABLE_FEATURE_PS_LONG |
746 | if (opts & OPT_l) { | 744 | if (opts & OPT_l) { |
747 | char bufr[6], stime_str[6]; | 745 | char bufr[6], stime_str[6]; |
@@ -752,8 +750,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
752 | time_t start = now - elapsed; | 750 | time_t start = now - elapsed; |
753 | struct tm *tm = localtime(&start); | 751 | struct tm *tm = localtime(&start); |
754 | 752 | ||
755 | smart_ulltoa5(p->rss, bufr, " mgtpezy"); | 753 | smart_ulltoa5(p->rss, bufr, " mgtpezy")[0] = '\0'; |
756 | bufr[5] = '\0'; | ||
757 | 754 | ||
758 | if (p->tty_major == 136) | 755 | if (p->tty_major == 136) |
759 | /* It should be pts/N, not ptsN, but N > 9 | 756 | /* It should be pts/N, not ptsN, but N > 9 |
diff --git a/procps/top.c b/procps/top.c index abee69806..a13a41cd8 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -847,8 +847,7 @@ static void display_topmem_header(int scr_width, int *lines_rem_p) | |||
847 | static void ulltoa6_and_space(unsigned long long ul, char buf[6]) | 847 | static void ulltoa6_and_space(unsigned long long ul, char buf[6]) |
848 | { | 848 | { |
849 | /* see http://en.wikipedia.org/wiki/Tera */ | 849 | /* see http://en.wikipedia.org/wiki/Tera */ |
850 | smart_ulltoa5(ul, buf, " mgtpezy"); | 850 | smart_ulltoa5(ul, buf, " mgtpezy")[0] = '\0'; |
851 | buf[5] = ' '; | ||
852 | } | 851 | } |
853 | 852 | ||
854 | static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) | 853 | static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) |
diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c index f45f68af0..5786d5f7d 100644 --- a/util-linux/fdisk_gpt.c +++ b/util-linux/fdisk_gpt.c | |||
@@ -93,9 +93,7 @@ gpt_list_table(int xtra UNUSED_PARAM) | |||
93 | int i; | 93 | int i; |
94 | char numstr6[6]; | 94 | char numstr6[6]; |
95 | 95 | ||
96 | numstr6[5] = '\0'; | 96 | smart_ulltoa5(total_number_of_sectors * sector_size, numstr6, " KMGTPEZY")[0] = '\0'; |
97 | |||
98 | smart_ulltoa5(total_number_of_sectors * sector_size, numstr6, " KMGTPEZY"); | ||
99 | printf("Disk %s: %llu sectors, %s\n", disk_device, | 97 | printf("Disk %s: %llu sectors, %s\n", disk_device, |
100 | (unsigned long long)total_number_of_sectors, | 98 | (unsigned long long)total_number_of_sectors, |
101 | numstr6); | 99 | numstr6); |
@@ -113,7 +111,7 @@ gpt_list_table(int xtra UNUSED_PARAM) | |||
113 | gpt_partition *p = gpt_part(i); | 111 | gpt_partition *p = gpt_part(i); |
114 | if (p->lba_start) { | 112 | if (p->lba_start) { |
115 | smart_ulltoa5((1 + SWAP_LE64(p->lba_end) - SWAP_LE64(p->lba_start)) * sector_size, | 113 | smart_ulltoa5((1 + SWAP_LE64(p->lba_end) - SWAP_LE64(p->lba_start)) * sector_size, |
116 | numstr6, " KMGTPEZY"); | 114 | numstr6, " KMGTPEZY")[0] = '\0'; |
117 | printf("%4u %15llu %15llu %11s %04x ", | 115 | printf("%4u %15llu %15llu %11s %04x ", |
118 | i + 1, | 116 | i + 1, |
119 | (unsigned long long)SWAP_LE64(p->lba_start), | 117 | (unsigned long long)SWAP_LE64(p->lba_start), |