diff --git a/src/tool_filetime.c b/src/tool_filetime.c index 054d34fe2e..9c2e80429b 100644 --- a/src/tool_filetime.c +++ b/src/tool_filetime.c @@ -32,9 +32,11 @@ # include #endif -curl_off_t getfiletime(const char *filename, struct GlobalConfig *global) +/* Returns 0 on success, non-zero on file problems */ +int getfiletime(const char *filename, struct GlobalConfig *global, + curl_off_t *stamp) { - curl_off_t result = -1; + int rc = 1; /* Windows stat() may attempt to adjust the unix GMT file time by a daylight saving time offset and since it's GMT that is bad behavior. When we have @@ -52,13 +54,13 @@ curl_off_t getfiletime(const char *filename, struct GlobalConfig *global) FILETIME ft; if(GetFileTime(hfile, NULL, NULL, &ft)) { curl_off_t converted = (curl_off_t)ft.dwLowDateTime - | ((curl_off_t)ft.dwHighDateTime) << 32; + | ((curl_off_t)ft.dwHighDateTime) << 32; - if(converted < CURL_OFF_T_C(116444736000000000)) { + if(converted < CURL_OFF_T_C(116444736000000000)) warnf(global, "Failed to get filetime: underflow"); - } else { - result = (converted - CURL_OFF_T_C(116444736000000000)) / 10000000; + *stamp = (converted - CURL_OFF_T_C(116444736000000000)) / 10000000; + rc = 0; } } else { @@ -76,13 +78,13 @@ curl_off_t getfiletime(const char *filename, struct GlobalConfig *global) #else struct_stat statbuf; if(-1 != stat(filename, &statbuf)) { - result = (curl_off_t)statbuf.st_mtime; + *stamp = (curl_off_t)statbuf.st_mtime; + rc = 0; } - else if(errno != ENOENT) { + else warnf(global, "Failed to get filetime: %s", strerror(errno)); - } #endif - return result; + return rc; } #if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || defined(WIN32) diff --git a/src/tool_filetime.h b/src/tool_filetime.h index 923ec06407..908b2d72bf 100644 --- a/src/tool_filetime.h +++ b/src/tool_filetime.h @@ -27,7 +27,8 @@ struct GlobalConfig; -curl_off_t getfiletime(const char *filename, struct GlobalConfig *global); +int getfiletime(const char *filename, struct GlobalConfig *global, + curl_off_t *stamp); #if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || \ (defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8)) diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 2e8d6d7b75..e4467628d5 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -2648,11 +2648,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ config->condtime = (curl_off_t)curl_getdate(nextarg, &now); if(-1 == config->condtime) { /* now let's see if it is a file name to get the time from instead! */ - curl_off_t filetime = getfiletime(nextarg, global); - if(filetime >= 0) { + curl_off_t filetime; + rc = getfiletime(nextarg, global, &filetime); + if(!rc) /* pull the time out from the file */ config->condtime = filetime; - } else { /* failed, remove time condition */ config->timecond = CURL_TIMECOND_NONE;