title: libcurl 404 detection
body: <p>I'm doing a file download with libcurl in my c++ program. How can i detect if the request is a 404, and not do the file write? The code is:</p>
  
  <pre><code>    void GameImage::DownloadImage(string file_name) {
      string game_name;
      game_name = file_name.substr(file_name.find_last_of("/")+1);
  
      CURL *curl;
      FILE *fp;
      CURLcode res;
      string url = "http://site/"+game_name+".png";
      string outfilename = file_name+".png";
      cout&lt;&lt;"INFO; attempting to download "&lt;&lt;url&lt;&lt;"..."&lt;&lt;endl;
      curl = curl_easy_init();
      if (curl) {
          cout&lt;&lt;"INFO; downloading "&lt;&lt;url&lt;&lt;"..."&lt;&lt;endl;
          fp = fopen(outfilename.c_str(), "wb");
          cout&lt;&lt;"INFO; trying to open "&lt;&lt;outfilename&lt;&lt;" for file output"&lt;&lt;endl;
          if (fp != NULL) {
              curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
              curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, GameImage::WriteData);
              curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
              curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
              curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
              res = curl_easy_perform(curl);
  
              long http_code = 0;
              curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &amp;http_code);
  
              curl_easy_cleanup(curl);
              fclose(fp);
          }
          else {
              cout&lt;&lt;"GameImage::DownloadImage; Couldn't open output file"&lt;&lt;endl;
          }
      }
  }
  
  size_t GameImage::WriteData(void *ptr, size_t size, size_t nmemb, FILE *stream) {
      size_t written;
      written = fwrite(ptr, size, nmemb, stream);
      return written;
  }
  </code></pre>
  
  <p>I can delete the 404 response after the transfer occurs, but it would be good to not even save the response.</p>