#include "base/time/time.h"
#include <stdint.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <limits>
#include "base/no_destructor.h"
#include "base/numerics/safe_math.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
#include "build/chromecast_buildflags.h"
#if BUILDFLAG(IS_ANDROID) && !defined(__LP64__)
#include <time64.h>
#endif
#if BUILDFLAG(IS_NACL)
#include "base/os_compat_nacl.h"
#endif
namespace {
base::Lock* GetSysTimeToTimeStructLock() { … }
#if BUILDFLAG(IS_ANDROID) && !defined(__LP64__)
typedef time64_t SysTime;
SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
base::AutoLock locked(*GetSysTimeToTimeStructLock());
if (is_local)
return mktime64(timestruct);
else
return timegm64(timestruct);
}
void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) {
base::AutoLock locked(*GetSysTimeToTimeStructLock());
if (is_local)
localtime64_r(&t, timestruct);
else
gmtime64_r(&t, timestruct);
}
#elif BUILDFLAG(IS_AIX)
time_t aix_timegm(struct tm* tm) {
time_t ret;
char* tz;
tz = getenv("TZ");
if (tz) {
tz = strdup(tz);
}
setenv("TZ", "GMT0", 1);
tzset();
ret = mktime(tm);
if (tz) {
setenv("TZ", tz, 1);
free(tz);
} else {
unsetenv("TZ");
}
tzset();
return ret;
}
typedef time_t SysTime;
SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
base::AutoLock locked(*GetSysTimeToTimeStructLock());
if (is_local)
return mktime(timestruct);
else
return aix_timegm(timestruct);
}
void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) {
base::AutoLock locked(*GetSysTimeToTimeStructLock());
if (is_local)
localtime_r(&t, timestruct);
else
gmtime_r(&t, timestruct);
}
#else
SysTime;
SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) { … }
void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) { … }
#endif
}
namespace base {
void Time::Explode(bool is_local, Exploded* exploded) const { … }
bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) { … }
}