From d53109eaa890ab807b66961a89291cea3cd3c003 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Tue, 18 Aug 2020 23:58:16 +0200 Subject: first part of a proper lutris implementation and cleanup - remove all old build platform related variables - change behavior of clean - change tabs into spaces - make XDG fetching method static - replace strcpy and cat with strn alternative with proper bounds checking - add cache dir - reenable dxvk and download from ram - completely rework lutris fetching and convert it into an interal struct - only show http errors in debug - add sanity checks to methods with possible NULL return - change extracting methods to extract tar from ram --- src/net.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/net.c') diff --git a/src/net.c b/src/net.c index a23f772..cf0488f 100644 --- a/src/net.c +++ b/src/net.c @@ -56,12 +56,14 @@ struct MemoryStruct* downloadToRam(const char* URL) curl_easy_getinfo (curl_handle, CURLINFO_RESPONSE_CODE, &http_code); if(res != CURLE_OK) { - printf("libcurl error: %s\n", curl_easy_strerror(res)); + puts(curl_easy_strerror(res)); return NULL; } else if (http_code != 200) { +#ifdef DEBUG printf("HTTP Error %li\n", http_code); +#endif return NULL; } @@ -79,8 +81,11 @@ void downloadFile(const char* URL, const char* path) if (chunk) { FILE* file = fopen(path, "wb"); - fwrite(chunk->memory, chunk->size, 1, file); - fclose(file); + if (file) + { + fwrite(chunk->memory, chunk->size, 1, file); + fclose(file); + } free(chunk->memory); free(chunk); @@ -91,15 +96,16 @@ struct json_object* fetchJSON(const char* URL) { struct MemoryStruct* chunk = downloadToRam(URL); + struct json_object* json = NULL; + if (chunk) { - struct json_object* json = json_tokener_parse((char*)chunk->memory); + json = json_tokener_parse((char*)chunk->memory); free(chunk->memory); free(chunk); - return json; } - return NULL; + return json; } \ No newline at end of file -- cgit v1.2.3