if (theModDate < -1) { Tcl_SetResult(interp, "Couldn't get resource modification date", TCL_STATIC); theResult = TCL_ERROR; break;
if (theResponseCode != 304) {  theCurlCode = curl_easy_getinfo(theHandle, CURLINFO_FILETIME, &theModDate); if (theCurlCode != CURLE_OK) { theResult = SetResultFromCurlErrorCode(interp, theCurlCode); break; }   curl_easy_cleanup( theHandle ); theHandle = NULL;   if (theModDate < -1) { Tcl_SetResult(interp, "Couldn't get resource modification date", TCL_STATIC); theResult = TCL_ERROR; break; }
CurlIsNewerCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]){	int theResult = TCL_OK;	CURL* theHandle = NULL;	FILE* theFile = NULL;	do {		long theResponseCode = 0;		const char* theURL;		const char* theDate;		CURLcode theCurlCode;		long theModDate;		long userModDate;						/*	first (second) parameter is the url,			second (third) parameter is the date */		if (objc != 4) {			Tcl_WrongNumArgs(interp, 1, objv, "isnewer url date");			theResult = TCL_ERROR;			break;		}		/* Retrieve the url */		theURL = Tcl_GetString(objv[2]);		/* Retrieve the date */		theDate = Tcl_GetString(objv[3]);				/* Convert the date (using libcurl) */		userModDate = (long) curl_getdate( theDate, NULL );		if (userModDate == -1) {			char theErrorString[512];			(void) snprintf(theErrorString, sizeof(theErrorString),				"Couldn't convert %s as a date", theDate);			Tcl_SetResult(interp, theErrorString, TCL_VOLATILE);			theResult = TCL_ERROR;			break;		}				/* Open the file (dev/null) */		theFile = fopen( "/dev/null", "a" );		if (theFile == NULL) {			Tcl_SetResult(interp, strerror(errno), TCL_VOLATILE);			theResult = TCL_ERROR;		}		/* Create the CURL handle */		theHandle = curl_easy_init();				/* Setup the handle */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_URL, theURL);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* -L option */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FOLLOWLOCATION, 1);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		/* -f option */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FAILONERROR, 1);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		/* write to the file */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_WRITEDATA, theFile);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* save the modification date */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FILETIME, 1);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		/* skip the download if the file wasn't modified */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_TIMEVALUE, userModDate);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}		/* we do not want any progress */		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_NOPROGRESS, 1);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* actually fetch the resource */		theCurlCode = curl_easy_perform(theHandle);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* close the file */		(void) fclose( theFile );		theFile = NULL;				/* check everything went fine */		theCurlCode = curl_easy_getinfo(theHandle, CURLINFO_RESPONSE_CODE, &theResponseCode);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* we need something between 200 (incl.) and 300 (excl.). */		if ((theResponseCode < 200) || (theResponseCode >= 300)) {			char theErrorString[512];			(void) snprintf(theErrorString, sizeof(theErrorString),				"Download failed (code = %li)", theResponseCode);			Tcl_SetResult(interp, theErrorString, TCL_VOLATILE);			theResult = TCL_ERROR;			break;		}		/* get the modification date */		theCurlCode = curl_easy_getinfo(theHandle, CURLINFO_FILETIME, &theModDate);		if (theCurlCode != CURLE_OK) {			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);			break;		}				/* clean up */		curl_easy_cleanup( theHandle );		theHandle = NULL;		/* compare this with the date provided by user */		if (theModDate < -1) {			Tcl_SetResult(interp, "Couldn't get resource modification date", TCL_STATIC);			theResult = TCL_ERROR;			break;		}		if (theModDate > userModDate) {			Tcl_SetResult(interp, "1", TCL_STATIC);		} else {			Tcl_SetResult(interp, "0", TCL_STATIC);		}		    } while (0);        if (theHandle != NULL) {    	curl_easy_cleanup( theHandle );    }    if (theFile != NULL) {    	fclose( theFile );    }    	return theResult;}