#include <curl.h>

int xfer_info_func(void *void_transfer_size, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
  (void)ultotal;
  (void)ulnow;

  curl_off_t *transfer_size = void_transfer_size;
  fprintf(stderr, "transfer_size=%jd, dltotal=%jd, dlnow=%jd\n", *transfer_size, dltotal, dlnow);

  return 0;
}

int main() {
  CURL *curl = curl_easy_init();

  curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/download/curl-7.40.0.tar.gz");
  curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, &xfer_info_func);
  curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0l);

  curl_off_t size1 = 524288;
  FILE *f1 = fopen("/tmp/1.part", "wb+");
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, f1);
  curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &size1);
  curl_easy_setopt(curl, CURLOPT_RANGE, "0-524287");


  if (curl_easy_perform(curl) != CURLE_OK) {
    fprintf(stderr, "transfer 1 failed.\n");
    return 1;
  }

  curl_off_t size2 = 262144;
  FILE *f2 = fopen("/tmp/2.part", "wb+");
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, f2);
  curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &size2);
  curl_easy_setopt(curl, CURLOPT_RANGE, "524288-786431");

  if (curl_easy_perform(curl) != CURLE_OK) {
    fprintf(stderr, "transfer 2 failed.\n");
    return 1;
  }

  curl_easy_cleanup(curl);
  return 0;
}

