mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-14 08:24:07 +00:00
Use clock_gettime instead of gettimeofday
This commit is contained in:
parent
c692093921
commit
32f096fa3f
@ -25,6 +25,13 @@
|
||||
#include <syslog.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef CLOCK_MONOTONIC_COARSE
|
||||
#define S3FS_CLOCK_MONOTONIC CLOCK_MONOTONIC_COARSE
|
||||
#else
|
||||
// case of OSX
|
||||
#define S3FS_CLOCK_MONOTONIC CLOCK_MONOTONIC
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// S3fsLog class
|
||||
//-------------------------------------------------------------------
|
||||
@ -74,10 +81,15 @@ class S3fsLog
|
||||
static const char* GetCurrentTime()
|
||||
{
|
||||
struct timeval now;
|
||||
struct timespec tsnow;
|
||||
struct tm res;
|
||||
char tmp[32];
|
||||
|
||||
if(-1 == clock_gettime(S3FS_CLOCK_MONOTONIC, &tsnow)){
|
||||
now.tv_sec = tsnow.tv_sec;
|
||||
now.tv_usec = (tsnow.tv_nsec / 1000);
|
||||
}else{
|
||||
gettimeofday(&now, NULL);
|
||||
}
|
||||
strftime(tmp, sizeof(tmp), "%Y-%m-%dT%H:%M:%S", gmtime_r(&now.tv_sec, &res));
|
||||
snprintf(current_time, sizeof(current_time), "%s.%03ldZ", tmp, (now.tv_usec / 1000));
|
||||
return current_time;
|
||||
|
Loading…
Reference in New Issue
Block a user