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.
This commit is contained in:
(≧◡≦) 2023-03-09 15:39:38 +01:00
parent a804518ef6
commit 82422e6d37
No known key found for this signature in database
GPG key ID: B39C0BCEE94A4A89
3 changed files with 27 additions and 10 deletions

View file

@ -1,8 +1,10 @@
#include <curl/system.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <libconfig.h> #include <libconfig.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <stdbool.h>
#include "sakisafecli.h" #include "sakisafecli.h"
size_t size_t
@ -37,16 +39,19 @@ print_help()
return; return;
} }
void size_t
progress( 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 */ /* I don't know why the fuck I have to do this */
dltotal += 1; if(ultotal == 0) {
dlnow += 1; ultotal++;
printf("\r%0.f uploaded of %0.f (\033[32;1m%0.f%%\033[30;0m)", }
struct progress *memory = (struct progress *)clientp;
printf("\r%li uploaded of %li (\033[32;1m%li%%\033[30;0m)",
ulnow, ulnow,
ultotal, ultotal,
ulnow * 100 / ultotal); ulnow * 100 / ultotal);
fflush(stdout); fflush(stdout);
return 0;
} }

View file

@ -194,7 +194,9 @@ main(int argc, char **argv)
/* Common options for both HTTP and SCP transfers */ /* Common options for both HTTP and SCP transfers */
curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, silent_flag); 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 */ /* File name */

View file

@ -2,6 +2,13 @@
#define SAKISAFECLI_H #define SAKISAFECLI_H
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <curl/curl.h>
struct progress
{
char *_private;
size_t size;
};
size_t size_t
write_data(void *buffer, size_t size, size_t nmemb, void *userp); 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 void
print_help(); print_help();
void size_t
progress( progress(void *clientp,
void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); curl_off_t dltotal,
curl_off_t dlnow,
curl_off_t ultotal,
curl_off_t ulnow);
void void
parse_config_file(FILE *config); parse_config_file(FILE *config);