mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-01-03 13:07:24 +00:00
Call std::get_time instead of strptime (#2598)
This reduces the Windows-specific code.
This commit is contained in:
parent
af0d7ba45e
commit
cc29bea81b
@ -254,7 +254,7 @@ time_t cvtIAMExpireStringToTime(const char* s)
|
|||||||
if(!s){
|
if(!s){
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
strptime(s, "%Y-%m-%dT%H:%M:%S", &tm);
|
s3fs_strptime(s, "%Y-%m-%dT%H:%M:%S", &tm);
|
||||||
return timegm(&tm); // GMT
|
return timegm(&tm); // GMT
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ time_t get_lastmodified(const char* s)
|
|||||||
if(!s){
|
if(!s){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strptime(s, "%a, %d %b %Y %H:%M:%S %Z", &tm);
|
s3fs_strptime(s, "%a, %d %b %Y %H:%M:%S %Z", &tm);
|
||||||
return timegm(&tm); // GMT
|
return timegm(&tm); // GMT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,23 +49,18 @@ std::string str(const struct timespec& value)
|
|||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __MSYS__
|
// This source code is from https://gist.github.com/jeremyfromearth/5694aa3a66714254752179ecf3c95582 .
|
||||||
/*
|
const char* s3fs_strptime(const char* s, const char* f, struct tm* tm)
|
||||||
* Polyfill for strptime function
|
|
||||||
*
|
|
||||||
* This source code is from https://gist.github.com/jeremyfromearth/5694aa3a66714254752179ecf3c95582 .
|
|
||||||
*/
|
|
||||||
char* strptime(const char* s, const char* f, struct tm* tm)
|
|
||||||
{
|
{
|
||||||
std::istringstream input(s);
|
std::istringstream input(s);
|
||||||
|
// TODO: call to setlocale required?
|
||||||
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
|
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
|
||||||
input >> std::get_time(tm, f);
|
input >> std::get_time(tm, f);
|
||||||
if (input.fail()) {
|
if (input.fail()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return (char*)(s + input.tellg());
|
return s + input.tellg();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
bool s3fs_strtoofft(off_t* value, const char* str, int base)
|
bool s3fs_strtoofft(off_t* value, const char* str, int base)
|
||||||
{
|
{
|
||||||
@ -303,7 +298,7 @@ bool get_unixtime_from_iso8601(const char* pdate, time_t& unixtime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
const char* prest = strptime(pdate, "%Y-%m-%dT%T", &tm);
|
const char* prest = s3fs_strptime(pdate, "%Y-%m-%dT%T", &tm);
|
||||||
if(prest == pdate){
|
if(prest == pdate){
|
||||||
// wrong format
|
// wrong format
|
||||||
return false;
|
return false;
|
||||||
|
@ -65,12 +65,10 @@ static inline const char* SAFESTRPTR(const char *strptr) { return strptr ? strpt
|
|||||||
// TODO: rename to to_string?
|
// TODO: rename to to_string?
|
||||||
std::string str(const struct timespec& value);
|
std::string str(const struct timespec& value);
|
||||||
|
|
||||||
#ifdef __MSYS__
|
|
||||||
//
|
//
|
||||||
// Polyfill for strptime function.
|
// Cross-platform strptime
|
||||||
//
|
//
|
||||||
char* strptime(const char* s, const char* f, struct tm* tm);
|
const char* s3fs_strptime(const char* s, const char* f, struct tm* tm);
|
||||||
#endif
|
|
||||||
//
|
//
|
||||||
// Convert string to off_t. Returns false on bad input.
|
// Convert string to off_t. Returns false on bad input.
|
||||||
// Replacement for C++11 std::stoll.
|
// Replacement for C++11 std::stoll.
|
||||||
|
Loading…
Reference in New Issue
Block a user