mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
Fix curl_off_t sized constants usage
This commit is contained in:
parent
9ee7a014c9
commit
4d1cd0da93
@ -23,14 +23,6 @@
|
|||||||
|
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#if defined(__EMX__)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
#include "sendf.h"
|
#include "sendf.h"
|
||||||
#include "progress.h"
|
#include "progress.h"
|
||||||
@ -68,53 +60,56 @@ static void time2str(char *r, long t)
|
|||||||
Add suffix k, M, G when suitable... */
|
Add suffix k, M, G when suitable... */
|
||||||
static char *max5data(curl_off_t bytes, char *max5)
|
static char *max5data(curl_off_t bytes, char *max5)
|
||||||
{
|
{
|
||||||
#define ONE_KILOBYTE 1024
|
#define ONE_KILOBYTE CURL_OFF_T_C(1024)
|
||||||
#define ONE_MEGABYTE (1024* ONE_KILOBYTE)
|
#define ONE_MEGABYTE (CURL_OFF_T_C(1024) * ONE_KILOBYTE)
|
||||||
#define ONE_GIGABYTE (1024* ONE_MEGABYTE)
|
#define ONE_GIGABYTE (CURL_OFF_T_C(1024) * ONE_MEGABYTE)
|
||||||
#define ONE_TERABYTE ((curl_off_t)1024* ONE_GIGABYTE)
|
#define ONE_TERABYTE (CURL_OFF_T_C(1024) * ONE_GIGABYTE)
|
||||||
#define ONE_PETABYTE ((curl_off_t)1024* ONE_TERABYTE)
|
#define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE)
|
||||||
|
|
||||||
if(bytes < 100000) {
|
if(bytes < CURL_OFF_T_C(100000))
|
||||||
snprintf(max5, 6, "%5" FORMAT_OFF_T, bytes);
|
snprintf(max5, 6, "%5" FORMAT_OFF_T, bytes);
|
||||||
}
|
|
||||||
else if(bytes < (10000*ONE_KILOBYTE)) {
|
else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE)
|
||||||
snprintf(max5, 6, "%4" FORMAT_OFF_T "k", (curl_off_t)(bytes/ONE_KILOBYTE));
|
snprintf(max5, 6, "%4" FORMAT_OFF_T "k", bytes/ONE_KILOBYTE);
|
||||||
}
|
|
||||||
else if(bytes < (100*ONE_MEGABYTE)) {
|
else if(bytes < CURL_OFF_T_C(100) * ONE_MEGABYTE)
|
||||||
/* 'XX.XM' is good as long as we're less than 100 megs */
|
/* 'XX.XM' is good as long as we're less than 100 megs */
|
||||||
snprintf(max5, 6, "%2d.%0dM",
|
snprintf(max5, 6, "%2" FORMAT_OFF_T ".%0" FORMAT_OFF_T "M",
|
||||||
(int)(bytes/ONE_MEGABYTE),
|
bytes/ONE_MEGABYTE,
|
||||||
(int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) );
|
(bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) );
|
||||||
}
|
|
||||||
#if CURL_SIZEOF_CURL_OFF_T > 4
|
#if CURL_SIZEOF_CURL_OFF_T > 4
|
||||||
else if(bytes < ( (curl_off_t)10000*ONE_MEGABYTE))
|
|
||||||
|
else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE)
|
||||||
/* 'XXXXM' is good until we're at 10000MB or above */
|
/* 'XXXXM' is good until we're at 10000MB or above */
|
||||||
snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE));
|
snprintf(max5, 6, "%4" FORMAT_OFF_T "M", bytes/ONE_MEGABYTE);
|
||||||
|
|
||||||
else if(bytes < (curl_off_t)100*ONE_GIGABYTE)
|
else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE)
|
||||||
/* 10000 MB - 100 GB, we show it as XX.XG */
|
/* 10000 MB - 100 GB, we show it as XX.XG */
|
||||||
snprintf(max5, 6, "%2d.%0dG",
|
snprintf(max5, 6, "%2" FORMAT_OFF_T ".%0" FORMAT_OFF_T "G",
|
||||||
(int)(bytes/ONE_GIGABYTE),
|
bytes/ONE_GIGABYTE,
|
||||||
(int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) );
|
(bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) );
|
||||||
|
|
||||||
else if(bytes < (curl_off_t)10000 * ONE_GIGABYTE)
|
else if(bytes < CURL_OFF_T_C(10000) * ONE_GIGABYTE)
|
||||||
/* up to 10000GB, display without decimal: XXXXG */
|
/* up to 10000GB, display without decimal: XXXXG */
|
||||||
snprintf(max5, 6, "%4dG", (int)(bytes/ONE_GIGABYTE));
|
snprintf(max5, 6, "%4" FORMAT_OFF_T "G", bytes/ONE_GIGABYTE);
|
||||||
|
|
||||||
else if(bytes < (curl_off_t)10000 * ONE_TERABYTE)
|
else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE)
|
||||||
/* up to 10000TB, display without decimal: XXXXT */
|
/* up to 10000TB, display without decimal: XXXXT */
|
||||||
snprintf(max5, 6, "%4dT", (int)(bytes/ONE_TERABYTE));
|
snprintf(max5, 6, "%4" FORMAT_OFF_T "T", bytes/ONE_TERABYTE);
|
||||||
else {
|
|
||||||
/* up to 10000PB, display without decimal: XXXXP */
|
|
||||||
snprintf(max5, 6, "%4dP", (int)(bytes/ONE_PETABYTE));
|
|
||||||
|
|
||||||
/* 16384 petabytes (16 exabytes) is maximum a 64 bit number can hold,
|
else
|
||||||
but this type is signed so 8192PB will be max.*/
|
/* up to 10000PB, display without decimal: XXXXP */
|
||||||
}
|
snprintf(max5, 6, "%4" FORMAT_OFF_T "P", bytes/ONE_PETABYTE);
|
||||||
|
|
||||||
|
/* 16384 petabytes (16 exabytes) is the maximum a 64 bit unsigned number
|
||||||
|
can hold, but our data type is signed so 8192PB will be the maximum. */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
else
|
else
|
||||||
snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE));
|
snprintf(max5, 6, "%4" FORMAT_OFF_T "M", bytes/ONE_MEGABYTE);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return max5;
|
return max5;
|
||||||
@ -316,7 +311,7 @@ int Curl_pgrsUpdate(struct connectdata *conn)
|
|||||||
curl_off_t amount = data->progress.speeder[nowindex]-
|
curl_off_t amount = data->progress.speeder[nowindex]-
|
||||||
data->progress.speeder[checkindex];
|
data->progress.speeder[checkindex];
|
||||||
|
|
||||||
if(amount > 4294967 /* 0xffffffff/1000 */)
|
if(amount > CURL_OFF_T_C(4294967) /* 0xffffffff/1000 */)
|
||||||
/* the 'amount' value is bigger than would fit in 32 bits if
|
/* the 'amount' value is bigger than would fit in 32 bits if
|
||||||
multiplied with 1000, so we use the double math for this */
|
multiplied with 1000, so we use the double math for this */
|
||||||
data->progress.current_speed = (curl_off_t)
|
data->progress.current_speed = (curl_off_t)
|
||||||
@ -324,7 +319,7 @@ int Curl_pgrsUpdate(struct connectdata *conn)
|
|||||||
else
|
else
|
||||||
/* the 'amount' value is small enough to fit within 32 bits even
|
/* the 'amount' value is small enough to fit within 32 bits even
|
||||||
when multiplied with 1000 */
|
when multiplied with 1000 */
|
||||||
data->progress.current_speed = amount*1000/span_ms;
|
data->progress.current_speed = amount*CURL_OFF_T_C(1000)/span_ms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user