* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
return result;
if(fstated) {
- const struct tm *tm;
time_t filetime = (time_t)statbuf.st_mtime;
-#ifdef HAVE_GMTIME_R
struct tm buffer;
- tm = (const struct tm *)gmtime_r(&filetime, &buffer);
-#else
- tm = gmtime(&filetime);
-#endif
+ const struct tm *tm = &buffer;
+ result = Curl_gmtime(filetime, &buffer);
+ if(result)
+ return result;
+
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
snprintf(buf, BUFSIZE-1,
"Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
ftpc->file &&
data->set.get_filetime &&
(data->info.filetime>=0) ) {
- struct tm *tm;
time_t filetime = (time_t)data->info.filetime;
-#ifdef HAVE_GMTIME_R
struct tm buffer;
- tm = (struct tm *)gmtime_r(&filetime, &buffer);
-#else
- tm = gmtime(&filetime);
-#endif
+ const struct tm *tm = &buffer;
+
+ result = Curl_gmtime(filetime, &buffer);
+ if(result)
+ return result;
+
/* format: "Tue, 15 Nov 1994 12:45:26" */
snprintf(buf, BUFSIZE-1,
"Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
const char *text,
time_t stamp)
{
- struct tm *tm;
-#ifdef HAVE_GMTIME_R
struct tm buffer;
- tm = (struct tm *)gmtime_r(&stamp, &buffer);
-#else
- tm = gmtime(&stamp);
-#endif
+ const struct tm *tm = &buffer;
+ CURLcode result = Curl_gmtime(stamp, &buffer);
+ if(result)
+ return;
+
snprintf(data->state.buffer,
BUFSIZE,
"\t %s: %s, %02d %s %4d %02d:%02d:%02d GMT\n",
CURLcode Curl_add_timecondition(struct SessionHandle *data,
Curl_send_buffer *req_buffer)
{
- struct tm *tm;
+ const struct tm *tm;
char *buf = data->state.buffer;
CURLcode result = CURLE_OK;
+ struct tm keeptime;
+
+ result = Curl_gmtime(data->set.timevalue, &keeptime);
+ if(result) {
+ failf(data, "Invalid TIMEVALUE\n");
+ return result;
+ }
+ tm = &keeptime;
/* The If-Modified-Since header family should have their times set in
* GMT as RFC2616 defines: "All HTTP date/time stamps MUST be
* Time)." (see page 20 of RFC2616).
*/
-#ifdef HAVE_GMTIME_R
- /* thread-safe version */
- struct tm keeptime;
- tm = (struct tm *)gmtime_r(&data->set.timevalue, &keeptime);
-#else
- tm = gmtime(&data->set.timevalue);
-#endif
-
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
snprintf(buf, BUFSIZE-1,
"%s, %02d %s %4d %02d:%02d:%02d GMT",
#endif
if(data->set.timecondition) {
- result = Curl_add_timecondition(data, req_buffer);
+ result = Curl_add_timecondition(data, req_buffer);
if(result)
return result;
}
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
/* everything else is fail */
return -1;
}
+
+CURLcode Curl_gmtime(time_t intime, struct tm *store)
+{
+ const struct tm *tm;
+#ifdef HAVE_GMTIME_R
+ /* thread-safe version */
+ tm = (struct tm *)(gmtime_r)(&intime, store);
+#else
+ tm = (gmtime)(&intime);
+ if(tm)
+ *store = *tm; /* copy the pointed struct to the local copy */
+#endif
+
+ if(!tm)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ return CURLE_OK;
+}
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
#define PARSEDATE_LATER 1
#define PARSEDATE_SOONER 2
+CURLcode Curl_gmtime(time_t intime, struct tm *store);
+
#endif