Fix: Fix curl errors. Curl was never used anyways

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2025-11-12 18:29:55 +00:00
parent 47e9700a4a
commit ad2591b33b
6 changed files with 12 additions and 84 deletions

View File

@ -93,6 +93,15 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/libraries/glad/src/glad.c)
)
endif()
# CURL (if vendored in libraries/)
if(EXISTS ${CMAKE_SOURCE_DIR}/libraries/curl/CMakeLists.txt)
add_subdirectory(${CMAKE_SOURCE_DIR}/libraries/curl EXCLUDE_FROM_ALL)
target_include_directories(${EXECUTABLE_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/libraries/curl/include
)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE curl)
endif()
# Link with OpenGL + dependencies
if (APPLE)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE glfw glad glm::glm "-framework OpenGL")

BIN
RASTER

Binary file not shown.

View File

@ -1,54 +0,0 @@
#include "http_get.h"
// Callback for libcurl to write response into our struct
static size_t write_callback(void *data, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
struct Memory *mem = (struct Memory *)userp;
char *ptr = realloc(mem->response, mem->size + realsize + 1);
if(ptr == NULL) {
// Out of memory!
fprintf(stderr, "realloc() failed\n");
return 0;
}
mem->response = ptr;
memcpy(&(mem->response[mem->size]), data, realsize);
mem->size += realsize;
mem->response[mem->size] = '\0';
return realsize;
}
// Function: GET request, returns heap string (caller must free)
char *http_get(const char *url) {
CURL *curl;
CURLcode res;
struct Memory chunk;
chunk.response = malloc(1); // start with empty buffer
chunk.size = 0;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); // follow redirects
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
free(chunk.response);
chunk.response = NULL;
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return chunk.response;
}

View File

@ -1,29 +0,0 @@
#ifndef HTTP_GET_H
#define HTTP_GET_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#ifdef __cplusplus
extern "C" {
#endif
// Struct to hold response data
struct Memory {
char *response;
size_t size;
};
// Callback for libcurl to write response into our struct
static size_t write_callback(void *data, size_t size, size_t nmemb, void *userp);
// Function: GET request, returns heap string (caller must free)
char *http_get(const char *url);
#ifdef __cplusplus
}
#endif
#endif // HTTP_GET_H

View File

@ -5,8 +5,8 @@
#include <stdlib.h>
// glad and GLFW
#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
// glm math
#include <glm/glm.hpp>

View File

@ -14,8 +14,10 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
// Shader loader helper
std::string loadShaderSource(const std::string& filepath);