title: uploading file with libcurl
body: <p>Take a look at the following code</p>
  
  <pre><code>static size_t reader(void *ptr, size_t size, size_t nmemb, FILE *stream) {
      size_t retcode = fread(ptr, size, nmemb, stream);
      cout &lt;&lt; "*** We read " &lt;&lt; retcode &lt;&lt; " bytes from file" &lt;&lt; endl;
      return retcode;
  }
  
  void upload() { //upload() is called from ouside
      FILE *pFile;
      pFile = fopen("map.txt" , "r");
  
      struct stat file_info;
      stat("map.txt", &amp;file_info);
      size_t size = (size_t)file_info.st_size;
      uploadFile(pFile, size);
  }
  
  bool uploadFile(void* data, size_t datasize) {
      CURL *curl;
      CURLcode res;
  
      curl = curl_easy_init();
      if (curl) {
          char *post_params = ...;
          curl_easy_setopt(curl, CURLOPT_URL, url);
          curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
          curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_params);
          curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(post_params));
          curl_easy_setopt(curl, CURLOPT_READFUNCTION, reader);
          curl_easy_setopt(curl, CURLOPT_READDATA, data);
          curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) datasize);
  
          res = curl_easy_perform(curl);
          curl_easy_cleanup(curl);
      }
      return true;
  }
  </code></pre>
  
  <p>When the code is executed, the following is outputed</p>
  
  <pre><code>*** We read 490 bytes from file
  *** We read 0 bytes from file
  </code></pre>
  
  <p>after that the app does nothing (even not exiting).</p>
  
  <p>Can someone point out at what's wrong here?</p>
  
  <p>Will be grateful for any help!!!</p>