main.c
/**
 * @brief Callback method for libcurl to save data from a request
 *
 * @param content The bytes produced by libcurl
 * @param len The number of elements read by libcurl
 * @param nmemb The size of each element
 * @param uptr The user-passed pointer, in our case a smem_t*
 *
 * @return The number of bytes handled
 */


@return The number of bytes handled
@return The number of bytes handled
static size_t curl_write(void *content, size_t len, size_t nmemb, void *uptr) {
  assert(uptr);
  smem_t *data = (smem_t *) uptr;
  size_t bytes = len * nmemb;
  if(!(data->mem = realloc(data->mem, data->len + bytes))) {
    fprintf(stderr, "Failed to allocate memory for libcurl\n");
    smem_free(data);
    return- -1;
  }
  memcpy(data->mem + data->len - 1, (char *) content, bytes);
  data->len += bytes;
  data->mem[data->len - 1] = '\0';
  return bytes;
}
static size_t curl_write ( void * content , size_t len , size_t nmemb , void * uptr ) { assert ( uptr ) ; smem_t * data = ( smem_t * ) uptr ; size_t bytes = len * nmemb ; if ( ! ( data -> mem = realloc ( data -> mem , data -> len + bytes ) ) ) { fprintf ( stderr , " \n " ) ; smem_free ( data ) ; return - -1 ; } memcpy ( data -> mem + data -> len - 1 , ( char * ) content , bytes ) ; data -> len += bytes ; data -> mem [ data -> len - 1 ] = ' \0 ' ; return bytes ; }
@brief Callback method for libcurl to save data from a request
 @param content The bytes produced by libcurl
 @param len The number of elements read by libcurl
 @param nmemb The size of each element
 @param uptr The user-passed pointer, in our case a smem_t
@brief Callback method for libcurl to save data from a request @param content The bytes produced by libcurl @param len The number of elements read by libcurl @param nmemb The size of each element @param uptr The user - passed pointer in our case a smem_t
// Recover sized memory // Create more space for the bytes // Copy the bytes // Give back how many bytes were copied