aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-12-18 21:38:18 +0100
committerJan200101 <sentrycraft123@gmail.com>2020-12-18 21:38:18 +0100
commit24288734e78aa2242b86dde8c770278fa1f5e05c (patch)
tree2da8381b426a93ddc9f71994dd2b8beba095b009
parent26dfafdb6c7411b0e6f3269cf1aa368bdc53a9ff (diff)
downloadpolecat-24288734e78aa2242b86dde8c770278fa1f5e05c.tar.gz
polecat-24288734e78aa2242b86dde8c770278fa1f5e05c.zip
add stderr checks, print carriage return when done downloading
- no reason to print out a progress bar when outputting to a descriptor - control over the current line is given back so whatever downloaded something can print whatever it wants on that line
-rw-r--r--src/net.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/net.c b/src/net.c
index cf0dfdf..e7397f6 100644
--- a/src/net.c
+++ b/src/net.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
+#include <unistd.h>
#include <curl/curl.h>
#include <json.h>
@@ -48,15 +49,20 @@ static int xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, UNUSED curl_o
fprintf(stderr, "\rProgress: %3" CURL_FORMAT_CURL_OFF_T "%%", progress);
+ if (progress == 100) fprintf(stderr, "\r");
+
return 0;
}
-struct MemoryStruct* downloadToRam(const char* URL, long progress)
+struct MemoryStruct* downloadToRam(const char* URL, long noprogress)
{
CURL* curl_handle;
CURLcode res = CURLE_OK;
struct progress prog;
+ if (!isatty(STDERR_FILENO))
+ noprogress = 1L;
+
struct MemoryStruct* chunk = malloc(sizeof(struct MemoryStruct));
if (chunk)
@@ -75,7 +81,7 @@ struct MemoryStruct* downloadToRam(const char* URL, long progress)
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, xferinfo);
curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &prog);
- curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, progress);
+ curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, noprogress);
res = curl_easy_perform(curl_handle);