From 82422e6d37b9cee270c716b8576abcc12b9b5819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Palomares=20Pizarro?= Date: Thu, 9 Mar 2023 15:39:38 +0100 Subject: [PATCH] Curl devs were very smart and decided to deprecated the CURL_PROGRESSFUNCTION option that had 0 problems in my opinion and decided to change it with CURL_XFERINFOFUNCTION thing which barely works and had to do a very weird workaround so I don't get a floating point exception just because. Well, it works and that's what matters. --- sakisafecli/funcs.c | 17 +++++++++++------ sakisafecli/sakisafecli.c | 4 +++- sakisafecli/sakisafecli.h | 16 +++++++++++++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/sakisafecli/funcs.c b/sakisafecli/funcs.c index b514ece..90be3e5 100644 --- a/sakisafecli/funcs.c +++ b/sakisafecli/funcs.c @@ -1,8 +1,10 @@ +#include #include #include #include #include #include +#include #include "sakisafecli.h" size_t @@ -37,16 +39,19 @@ print_help() return; } -void +size_t progress( - void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) + void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { - /* So I don't get a warning */ - dltotal += 1; - dlnow += 1; - printf("\r%0.f uploaded of %0.f (\033[32;1m%0.f%%\033[30;0m)", + /* I don't know why the fuck I have to do this */ + if(ultotal == 0) { + ultotal++; + } + struct progress *memory = (struct progress *)clientp; + printf("\r%li uploaded of %li (\033[32;1m%li%%\033[30;0m)", ulnow, ultotal, ulnow * 100 / ultotal); fflush(stdout); + return 0; } diff --git a/sakisafecli/sakisafecli.c b/sakisafecli/sakisafecli.c index 40f95ce..3c4e94f 100644 --- a/sakisafecli/sakisafecli.c +++ b/sakisafecli/sakisafecli.c @@ -194,7 +194,9 @@ main(int argc, char **argv) /* Common options for both HTTP and SCP transfers */ curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, silent_flag); - curl_easy_setopt(easy_handle, CURLOPT_PROGRESSFUNCTION, progress); + struct progress mem; + curl_easy_setopt(easy_handle, CURLOPT_XFERINFODATA, &mem); + curl_easy_setopt(easy_handle, CURLOPT_XFERINFOFUNCTION, progress); /* File name */ diff --git a/sakisafecli/sakisafecli.h b/sakisafecli/sakisafecli.h index 90589f4..6b17f60 100644 --- a/sakisafecli/sakisafecli.h +++ b/sakisafecli/sakisafecli.h @@ -2,6 +2,13 @@ #define SAKISAFECLI_H #include #include +#include + +struct progress +{ + char *_private; + size_t size; +}; size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp); @@ -15,9 +22,12 @@ store_link(const char *path, const char *buf); void print_help(); -void -progress( - void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); +size_t +progress(void *clientp, + curl_off_t dltotal, + curl_off_t dlnow, + curl_off_t ultotal, + curl_off_t ulnow); void parse_config_file(FILE *config);