mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-05-29 07:00:49 +00:00
Revert "Call C++11 get_time and put_time (#2375)"
This reverts commit 10a72bfd0f
. These
commit is incompatible with older CentOS 7 libstdc++.
This commit is contained in:
parent
2b57e74330
commit
2703cecf73
|
@ -19,8 +19,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iomanip>
|
|
||||||
#include <sstream>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -256,8 +254,8 @@ time_t cvtIAMExpireStringToTime(const char* s)
|
||||||
if(!s){
|
if(!s){
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
std::istringstream ss(s);
|
memset(&tm, 0, sizeof(struct tm));
|
||||||
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%S");
|
strptime(s, "%Y-%m-%dT%H:%M:%S", &tm);
|
||||||
return timegm(&tm); // GMT
|
return timegm(&tm); // GMT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +265,8 @@ time_t get_lastmodified(const char* s)
|
||||||
if(!s){
|
if(!s){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::istringstream ss(s);
|
memset(&tm, 0, sizeof(struct tm));
|
||||||
ss >> std::get_time(&tm, "%a, %d %b %Y %H:%M:%S %Z");
|
strptime(s, "%a, %d %b %Y %H:%M:%S %Z", &tm);
|
||||||
return timegm(&tm); // GMT
|
return timegm(&tm); // GMT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,15 @@ std::string S3fsLog::GetCurrentTime()
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
struct timespec tsnow;
|
struct timespec tsnow;
|
||||||
struct tm res;
|
struct tm res;
|
||||||
|
char tmp[32];
|
||||||
if(-1 == clock_gettime(S3FS_CLOCK_MONOTONIC, &tsnow)){
|
if(-1 == clock_gettime(S3FS_CLOCK_MONOTONIC, &tsnow)){
|
||||||
now.tv_sec = tsnow.tv_sec;
|
now.tv_sec = tsnow.tv_sec;
|
||||||
now.tv_usec = (tsnow.tv_nsec / 1000);
|
now.tv_usec = (tsnow.tv_nsec / 1000);
|
||||||
}else{
|
}else{
|
||||||
gettimeofday(&now, nullptr);
|
gettimeofday(&now, nullptr);
|
||||||
}
|
}
|
||||||
current_time << std::put_time(gmtime_r(&now.tv_sec, &res), "%Y-%m-%dT%H:%M:%S")
|
strftime(tmp, sizeof(tmp), "%Y-%m-%dT%H:%M:%S", gmtime_r(&now.tv_sec, &res));
|
||||||
<< "." << std::setfill('0') << std::setw(3) << (now.tv_usec / 1000) << "Z ";
|
current_time << tmp << "." << std::setfill('0') << std::setw(3) << (now.tv_usec / 1000) << "Z ";
|
||||||
}
|
}
|
||||||
return current_time.str();
|
return current_time.str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "s3fs_logger.h"
|
#include "s3fs_logger.h"
|
||||||
|
@ -46,6 +47,24 @@ std::string str(const struct timespec value)
|
||||||
return s.str();
|
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)
|
||||||
|
{
|
||||||
|
std::istringstream input(s);
|
||||||
|
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
|
||||||
|
input >> std::get_time(tm, f);
|
||||||
|
if (input.fail()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return (char*)(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)
|
||||||
{
|
{
|
||||||
if(value == nullptr || str == nullptr){
|
if(value == nullptr || str == nullptr){
|
||||||
|
@ -240,11 +259,11 @@ bool get_keyword_value(const std::string& target, const char* keyword, std::stri
|
||||||
//
|
//
|
||||||
std::string get_date_rfc850()
|
std::string get_date_rfc850()
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
char buf[100];
|
||||||
time_t t = time(nullptr);
|
time_t t = time(nullptr);
|
||||||
struct tm res;
|
struct tm res;
|
||||||
ss << std::put_time(gmtime_r(&t, &res), "%a, %d %b %Y %H:%M:%S GMT");
|
strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime_r(&t, &res));
|
||||||
return ss.str();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_date_sigv3(std::string& date, std::string& date8601)
|
void get_date_sigv3(std::string& date, std::string& date8601)
|
||||||
|
@ -256,18 +275,18 @@ void get_date_sigv3(std::string& date, std::string& date8601)
|
||||||
|
|
||||||
std::string get_date_string(time_t tm)
|
std::string get_date_string(time_t tm)
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
char buf[100];
|
||||||
struct tm res;
|
struct tm res;
|
||||||
ss << std::put_time(gmtime_r(&tm, &res), "%Y%m%d");
|
strftime(buf, sizeof(buf), "%Y%m%d", gmtime_r(&tm, &res));
|
||||||
return ss.str();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_date_iso8601(time_t tm)
|
std::string get_date_iso8601(time_t tm)
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
char buf[100];
|
||||||
struct tm res;
|
struct tm res;
|
||||||
s << std::put_time(gmtime_r(&tm, &res), "%Y%m%dT%H%M%SZ");
|
strftime(buf, sizeof(buf), "%Y%m%dT%H%M%SZ", gmtime_r(&tm, &res));
|
||||||
return s.str();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_unixtime_from_iso8601(const char* pdate, time_t& unixtime)
|
bool get_unixtime_from_iso8601(const char* pdate, time_t& unixtime)
|
||||||
|
@ -277,9 +296,8 @@ bool get_unixtime_from_iso8601(const char* pdate, time_t& unixtime)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
std::istringstream ss(pdate);
|
const char* prest = strptime(pdate, "%Y-%m-%dT%T", &tm);
|
||||||
ss >> std::get_time(&tm, "%Y-%m-%dT%T");
|
if(prest == pdate){
|
||||||
if(ss.fail()){
|
|
||||||
// wrong format
|
// wrong format
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,12 @@ 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.
|
||||||
|
//
|
||||||
|
char* 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