aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorBradley M. Kuhn <bkuhn@ebb.org>2010-08-08 02:51:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-08-08 02:51:20 +0200
commitc97131c2af832f03e769a12b2a95e4de86c5858f (patch)
tree6bb49cd582b75953c822431162a94809a9539918 /libbb
parent33bbb27e45c7c6a0fecb40b3a5aa36aef69825f9 (diff)
downloadbusybox-w32-c97131c2af832f03e769a12b2a95e4de86c5858f.tar.gz
busybox-w32-c97131c2af832f03e769a12b2a95e4de86c5858f.tar.bz2
busybox-w32-c97131c2af832f03e769a12b2a95e4de86c5858f.zip
wget: implement -T SEC; rework progress meter to not use signals (it was unsafe)
function old new delta retrieve_file_data 364 450 +86 bb_progress_update 615 682 +67 packed_usage 27406 27422 +16 wget_main 2440 2453 +13 static.wget_longopts 145 155 +10 progress_meter 199 159 -40 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/1 up/down: 192/-40) Total: 152 bytes Signed-off-by: Bradley M. Kuhn <bkuhn@ebb.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/progress.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/libbb/progress.c b/libbb/progress.c
index e96039042..7fb8536d2 100644
--- a/libbb/progress.c
+++ b/libbb/progress.c
@@ -66,16 +66,29 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
66 off_t transferred, 66 off_t transferred,
67 off_t totalsize) 67 off_t totalsize)
68{ 68{
69 off_t abbrevsize; 69 uoff_t beg_and_transferred;
70 unsigned since_last_update, elapsed; 70 unsigned since_last_update, elapsed;
71 unsigned ratio; 71 unsigned ratio;
72 int barlength, i; 72 int barlength, i;
73 73
74 /* totalsize == 0 if it is unknown */
75
76 elapsed = monotonic_sec();
77 since_last_update = elapsed - p->lastupdate_sec;
78 /* Do not update on every call
79 * (might be: on every network read!) */
80 if (since_last_update == 0 && !totalsize)
81 return;
82
83 beg_and_transferred = beg_range + transferred;
74 ratio = 100; 84 ratio = 100;
75 if (totalsize) { 85 if (beg_and_transferred < totalsize) {
86 /* Do not update on every call
87 * (might be: on every network read!) */
88 if (since_last_update == 0)
89 return;
76 /* long long helps to have it working even if !LFS */ 90 /* long long helps to have it working even if !LFS */
77 ratio = (unsigned) (100ULL * (transferred+beg_range) / totalsize); 91 ratio = 100ULL * beg_and_transferred / (uoff_t)totalsize;
78 if (ratio > 100) ratio = 100;
79 } 92 }
80 93
81#if ENABLE_UNICODE_SUPPORT 94#if ENABLE_UNICODE_SUPPORT
@@ -95,11 +108,11 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
95 /* back to multibyte; cant overflow */ 108 /* back to multibyte; cant overflow */
96 wcstombs(buf, wbuf21, INT_MAX); 109 wcstombs(buf, wbuf21, INT_MAX);
97 len = (len > 20) ? 0 : 20 - len; 110 len = (len > 20) ? 0 : 20 - len;
98 fprintf(stderr, "\r%s%*s%4d%% ", buf, len, "", ratio); 111 fprintf(stderr, "\r%s%*s%4u%% ", buf, len, "", ratio);
99 free(buf); 112 free(buf);
100 } 113 }
101#else 114#else
102 fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio); 115 fprintf(stderr, "\r%-20.20s%4u%% ", curfile, ratio);
103#endif 116#endif
104 117
105 barlength = get_tty2_width() - 49; 118 barlength = get_tty2_width() - 49;
@@ -114,16 +127,14 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
114 } 127 }
115 } 128 }
116 i = 0; 129 i = 0;
117 abbrevsize = transferred + beg_range; 130 while (beg_and_transferred >= 100000) {
118 while (abbrevsize >= 100000) {
119 i++; 131 i++;
120 abbrevsize >>= 10; 132 beg_and_transferred >>= 10;
121 } 133 }
122 /* see http://en.wikipedia.org/wiki/Tera */ 134 /* see http://en.wikipedia.org/wiki/Tera */
123 fprintf(stderr, "%6d%c ", (int)abbrevsize, " kMGTPEZY"[i]); 135 fprintf(stderr, "%6u%c ", (unsigned)beg_and_transferred, " kMGTPEZY"[i]);
136#define beg_and_transferred dont_use_beg_and_transferred_below
124 137
125 elapsed = monotonic_sec();
126 since_last_update = elapsed - p->lastupdate_sec;
127 if (transferred > p->lastsize) { 138 if (transferred > p->lastsize) {
128 p->lastupdate_sec = elapsed; 139 p->lastupdate_sec = elapsed;
129 p->lastsize = transferred; 140 p->lastsize = transferred;