Call std::get_time instead of strptime (#2598)
This reduces the Windows-specific code.
This commit is contained in:
@ -49,23 +49,18 @@ std::string str(const struct timespec& value)
|
||||
return s.str();
|
||||
}
|
||||
|
||||
#ifdef __MSYS__
|
||||
/*
|
||||
* 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)
|
||||
// This source code is from https://gist.github.com/jeremyfromearth/5694aa3a66714254752179ecf3c95582 .
|
||||
const char* s3fs_strptime(const char* s, const char* f, struct tm* tm)
|
||||
{
|
||||
std::istringstream input(s);
|
||||
// TODO: call to setlocale required?
|
||||
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
|
||||
input >> std::get_time(tm, f);
|
||||
if (input.fail()) {
|
||||
return nullptr;
|
||||
}
|
||||
return (char*)(s + input.tellg());
|
||||
return s + input.tellg();
|
||||
}
|
||||
#endif
|
||||
|
||||
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;
|
||||
const char* prest = strptime(pdate, "%Y-%m-%dT%T", &tm);
|
||||
const char* prest = s3fs_strptime(pdate, "%Y-%m-%dT%T", &tm);
|
||||
if(prest == pdate){
|
||||
// wrong format
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user