system.h: remove some macros

Since curl_off_t is always 64 bit these days, we can simplify and avoid
using some macros.

Closes #17498
This commit is contained in:
Daniel Stenberg 2025-05-31 18:47:23 +02:00
parent 68c02e6ab7
commit 614313f12f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
14 changed files with 149 additions and 213 deletions

View file

@ -937,7 +937,7 @@ CURLcode config2setopts(struct GlobalConfig *global,
if(config->use_resume)
my_setopt_offt(curl, CURLOPT_RESUME_FROM_LARGE, config->resume_from);
else
my_setopt_offt(curl, CURLOPT_RESUME_FROM_LARGE, CURL_OFF_T_C(0));
my_setopt_offt(curl, CURLOPT_RESUME_FROM_LARGE, 0);
my_setopt_str(curl, CURLOPT_KEYPASSWD, config->key_passwd);
my_setopt_str(curl, CURLOPT_PROXY_KEYPASSWD, config->proxy_key_passwd);

View file

@ -115,7 +115,7 @@ static void fly(struct ProgressData *bar, bool moved)
#error "too small curl_off_t"
#else
/* assume SIZEOF_CURL_OFF_T == 8 */
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
# define CURL_OFF_T_MAX 0x7FFFFFFFFFFFFFFF
#endif
static void update_width(struct ProgressData *bar)

View file

@ -49,7 +49,7 @@ int tool_seek_cb(void *userdata, curl_off_t offset, int whence)
using a 'long' data type offset */
#define OUR_MAX_SEEK_L 2147483647L - 1L
#define OUR_MAX_SEEK_O CURL_OFF_T_C(0x7FFFFFFF) - CURL_OFF_T_C(0x1)
#define OUR_MAX_SEEK_O 0x7FFFFFFF - 0x1
/* The offset check following here is only interesting if curl_off_t is
larger than off_t and we are not using the Win32 large file support

View file

@ -46,9 +46,9 @@ int getfiletime(const char *filename, struct GlobalConfig *global,
TCHAR *tchar_filename = curlx_convert_UTF8_to_tchar(filename);
hfile = CreateFile(tchar_filename, FILE_READ_ATTRIBUTES,
(FILE_SHARE_READ | FILE_SHARE_WRITE |
FILE_SHARE_DELETE),
NULL, OPEN_EXISTING, 0, NULL);
(FILE_SHARE_READ | FILE_SHARE_WRITE |
FILE_SHARE_DELETE),
NULL, OPEN_EXISTING, 0, NULL);
curlx_unicodefree(tchar_filename);
if(hfile != INVALID_HANDLE_VALUE) {
FILETIME ft;
@ -56,10 +56,10 @@ int getfiletime(const char *filename, struct GlobalConfig *global,
curl_off_t converted = (curl_off_t)ft.dwLowDateTime
| ((curl_off_t)ft.dwHighDateTime) << 32;
if(converted < CURL_OFF_T_C(116444736000000000))
if(converted < 116444736000000000)
warnf(global, "Failed to get filetime: underflow");
else {
*stamp = (converted - CURL_OFF_T_C(116444736000000000)) / 10000000;
*stamp = (converted - 116444736000000000) / 10000000;
rc = 0;
}
}
@ -101,7 +101,7 @@ void setfiletime(curl_off_t filetime, const char *filename,
/* 910670515199 is the maximum Unix filetime that can be used as a
Windows FILETIME without overflow: 30827-12-31T23:59:59. */
if(filetime > CURL_OFF_T_C(910670515199)) {
if(filetime > 910670515199) {
warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on outfile: overflow", filetime);
curlx_unicodefree(tchar_filename);
@ -115,7 +115,7 @@ void setfiletime(curl_off_t filetime, const char *filename,
curlx_unicodefree(tchar_filename);
if(hfile != INVALID_HANDLE_VALUE) {
curl_off_t converted = ((curl_off_t)filetime * 10000000) +
CURL_OFF_T_C(116444736000000000);
116444736000000000;
FILETIME ft;
ft.dwLowDateTime = (DWORD)(converted & 0xFFFFFFFF);
ft.dwHighDateTime = (DWORD)(converted >> 32);

View file

@ -32,39 +32,39 @@
Add suffix k, M, G when suitable... */
static char *max5data(curl_off_t bytes, char *max5)
{
#define ONE_KILOBYTE CURL_OFF_T_C(1024)
#define ONE_MEGABYTE (CURL_OFF_T_C(1024) * ONE_KILOBYTE)
#define ONE_GIGABYTE (CURL_OFF_T_C(1024) * ONE_MEGABYTE)
#define ONE_TERABYTE (CURL_OFF_T_C(1024) * ONE_GIGABYTE)
#define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE)
#define ONE_KILOBYTE (curl_off_t)1024
#define ONE_MEGABYTE (1024 * ONE_KILOBYTE)
#define ONE_GIGABYTE (1024 * ONE_MEGABYTE)
#define ONE_TERABYTE (1024 * ONE_GIGABYTE)
#define ONE_PETABYTE (1024 * ONE_TERABYTE)
if(bytes < CURL_OFF_T_C(100000))
if(bytes < 100000)
msnprintf(max5, 6, "%5" CURL_FORMAT_CURL_OFF_T, bytes);
else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE)
else if(bytes < 10000 * ONE_KILOBYTE)
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "k", bytes/ONE_KILOBYTE);
else if(bytes < CURL_OFF_T_C(100) * ONE_MEGABYTE)
else if(bytes < 100 * ONE_MEGABYTE)
/* 'XX.XM' is good as long as we are less than 100 megs */
msnprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0"
CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE,
(bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) );
(bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/10) );
else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE)
else if(bytes < 10000 * ONE_MEGABYTE)
/* 'XXXXM' is good until we are at 10000MB or above */
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE);
else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE)
else if(bytes < 100 * ONE_GIGABYTE)
/* 10000 MB - 100 GB, we show it as XX.XG */
msnprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0"
CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE,
(bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) );
(bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/10) );
else if(bytes < CURL_OFF_T_C(10000) * ONE_GIGABYTE)
else if(bytes < 10000 * ONE_GIGABYTE)
/* up to 10000GB, display without decimal: XXXXG */
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE);
else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE)
else if(bytes < 10000 * ONE_TERABYTE)
/* up to 10000TB, display without decimal: XXXXT */
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "T", bytes/ONE_TERABYTE);
@ -110,19 +110,19 @@ static void time2str(char *r, curl_off_t seconds)
strcpy(r, "--:--:--");
return;
}
h = seconds / CURL_OFF_T_C(3600);
if(h <= CURL_OFF_T_C(99)) {
curl_off_t m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60);
curl_off_t s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60));
h = seconds / 3600;
if(h <= 99) {
curl_off_t m = (seconds - (h * 3600)) / 60;
curl_off_t s = (seconds - (h * 3600)) - (m * 60);
msnprintf(r, 9, "%2" CURL_FORMAT_CURL_OFF_T ":%02" CURL_FORMAT_CURL_OFF_T
":%02" CURL_FORMAT_CURL_OFF_T, h, m, s);
}
else {
/* this equals to more than 99 hours, switch to a more suitable output
format to fit within the limits. */
curl_off_t d = seconds / CURL_OFF_T_C(86400);
h = (seconds - (d*CURL_OFF_T_C(86400))) / CURL_OFF_T_C(3600);
if(d <= CURL_OFF_T_C(999))
curl_off_t d = seconds / 86400;
h = (seconds - (d * 86400)) / 3600;
if(d <= 999)
msnprintf(r, 9, "%3" CURL_FORMAT_CURL_OFF_T
"d %02" CURL_FORMAT_CURL_OFF_T "h", d, h);
else