Mercurial > gftp.yaz
comparison src/gtk/transfer.c @ 246:290d00853950
2003-8-4 Brian Masney <masneyb@gftp.org>
* src/gtk/transfer.c (update_file_status) - fix possible division by 0
author | masneyb |
---|---|
date | Tue, 05 Aug 2003 01:54:03 +0000 |
parents | 251845fc1ef1 |
children | 2ad324cf4930 |
comparison
equal
deleted
inserted
replaced
245:41af60bc1f88 | 246:290d00853950 |
---|---|
1291 static void | 1291 static void |
1292 update_file_status (gftp_transfer * tdata) | 1292 update_file_status (gftp_transfer * tdata) |
1293 { | 1293 { |
1294 char totstr[100], dlstr[100], gotstr[50], ofstr[50]; | 1294 char totstr[100], dlstr[100], gotstr[50], ofstr[50]; |
1295 int hours, mins, secs, pcent, st; | 1295 int hours, mins, secs, pcent, st; |
1296 off_t remaining_secs; | 1296 unsigned long remaining_secs, lkbs; |
1297 gftp_file * tempfle; | 1297 gftp_file * tempfle; |
1298 struct timeval tv; | 1298 struct timeval tv; |
1299 | 1299 |
1300 g_static_mutex_lock (&tdata->statmutex); | 1300 g_static_mutex_lock (&tdata->statmutex); |
1301 tempfle = tdata->curfle->data; | 1301 tempfle = tdata->curfle->data; |
1302 | 1302 |
1303 gettimeofday (&tv, NULL); | 1303 gettimeofday (&tv, NULL); |
1304 | 1304 |
1305 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; | 1305 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; |
1306 if (tdata->kbs > 0) | 1306 |
1307 remaining_secs /= (off_t) tdata->kbs; | 1307 lkbs = (unsigned long) tdata->kbs; |
1308 if (lkbs > 0) | |
1309 remaining_secs /= lkbs; | |
1308 | 1310 |
1309 hours = remaining_secs / 3600; | 1311 hours = remaining_secs / 3600; |
1310 remaining_secs -= hours * 3600; | 1312 remaining_secs -= hours * 3600; |
1311 mins = remaining_secs / 60; | 1313 mins = remaining_secs / 60; |
1312 remaining_secs -= mins * 60; | 1314 remaining_secs -= mins * 60; |
1316 { | 1318 { |
1317 g_static_mutex_unlock (&tdata->statmutex); | 1319 g_static_mutex_unlock (&tdata->statmutex); |
1318 return; | 1320 return; |
1319 } | 1321 } |
1320 | 1322 |
1321 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | 1323 if ((double) tdata->total_bytes > 0) |
1322 if (pcent < 0 || pcent > 100) | 1324 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); |
1325 else | |
1323 pcent = 0; | 1326 pcent = 0; |
1324 | 1327 |
1325 g_snprintf (totstr, sizeof (totstr), | 1328 g_snprintf (totstr, sizeof (totstr), |
1326 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), | 1329 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1327 pcent, hours, mins, secs, tdata->current_file_number, | 1330 pcent, hours, mins, secs, tdata->current_file_number, |
1336 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | 1339 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) |
1337 { | 1340 { |
1338 if (tdata->curfle->next != NULL) | 1341 if (tdata->curfle->next != NULL) |
1339 { | 1342 { |
1340 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; | 1343 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
1341 if (tdata->kbs > 0) | 1344 |
1342 remaining_secs /= (off_t) tdata->kbs; | 1345 lkbs = (unsigned long) tdata->kbs; |
1346 if (lkbs > 0) | |
1347 remaining_secs /= lkbs; | |
1343 | 1348 |
1344 hours = remaining_secs / 3600; | 1349 hours = remaining_secs / 3600; |
1345 remaining_secs -= hours * 3600; | 1350 remaining_secs -= hours * 3600; |
1346 mins = remaining_secs / 60; | 1351 mins = remaining_secs / 60; |
1347 remaining_secs -= mins * 60; | 1352 remaining_secs -= mins * 60; |