m3core/src/unix/Common/UtimeC.c
#include "m3unix.h"
#ifdef __cplusplus
extern "C" {
#endif
void Utime__Assertions(void)
{
#ifndef _WIN32
/* Basically no 32bit system has a 64bit time_t, unfortunate. */
M3_STATIC_ASSERT(sizeof(time_t) <= sizeof(void*));
/* verify itimerval contains just the two fields we know about, in either order */
{ typedef itimerval_t T;
M3_STATIC_ASSERT(sizeof(T) == M3_FIELD_SIZE(T, it_value) + M3_FIELD_SIZE(T, it_interval)); }
/* verify timespec (nanotime) contains just the two fields we know about, in either order */
{ typedef timespec_T T;
M3_STATIC_ASSERT(sizeof(T) == M3_FIELD_SIZE(T, tv_sec) + M3_FIELD_SIZE(T, tv_nsec)); }
/* verify timeval (microtime) contains just the two fields we know about, in either order */
#if defined(__APPLE__) && defined(__x86_64__)
/* AMD64_DARWIN has:
struct timeval
{
int64 tv_sec;
int32 tv_usec;
4 bytes of padding
}; I do not see much we can do about this. We use copying wrappers and we
want to be sure they are copying the entire struct.
*/
{ typedef timeval_t T1;
typedef struct { time_t tv_sec; suseconds_t tv_usec; } T2;
M3_STATIC_ASSERT(M3_FIELD_SIZE(T1, tv_sec) == 8);
M3_STATIC_ASSERT(M3_FIELD_SIZE(T1, tv_usec) == 4);
M3_STATIC_ASSERT(M3_FIELD_SIZE(T2, tv_sec) == 8);
M3_STATIC_ASSERT(M3_FIELD_SIZE(T2, tv_usec) == 4);
M3_STATIC_ASSERT(sizeof(T1) == 16);
M3_STATIC_ASSERT(sizeof(T2) == 16);
}
#else
{ typedef timeval_t T;
M3_STATIC_ASSERT(sizeof(T) == M3_FIELD_SIZE(T, tv_sec) + M3_FIELD_SIZE(T, tv_usec)); }
#endif
/* verify timezone is exactly as we expect */
{ typedef m3_timezone_t M;
typedef timezone_t T;
M3_STATIC_ASSERT(sizeof(T) == sizeof(M));
M3_STATIC_ASSERT(sizeof(T) == 8);
M3_STATIC_ASSERT(offsetof(T, tz_minuteswest) == 0);
M3_STATIC_ASSERT(offsetof(T, tz_dsttime) == 4);
M3_STATIC_ASSERT(offsetof(M, minuteswest) == 0);
M3_STATIC_ASSERT(offsetof(M, dsttime) == 4);
}
#endif
}
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
#define M3BSD
#endif
/*
wrap up global variables in functions until something else is done
*/
#ifndef M3BSD
time_t Utime__get_timezone(void)
{
#ifdef __CYGWIN__
return _timezone;
#else
return timezone;
#endif
}
#if defined(__CYGWIN__) || defined(__sun) || defined(__hpux) || defined(__INTERIX)
time_t Utime__get_altzone(void)
{
#ifdef __sun
return altzone;
#else
/* based on Python's timemodule */
return Utime__get_timezone() - 3600;
#endif
}
#endif /* cygwin | sun */
int Utime__get_daylight(void)
{
#ifdef __CYGWIN__
return _daylight;
#else
return daylight;
#endif
}
const char* Utime__get_tzname(unsigned a)
{
assert((a == 0) || (a == 1));
return tzname[a & 1];
}
#endif /* M3BSD */
#ifndef _WIN32
int Utime__gettimeofday (timeval_t* t, timezone_t* z)
{
return gettimeofday(t, z);
}
int Utime__settimeofday (timeval_t* t, timezone_t* z)
{
return settimeofday(t, z);
}
int Utime__getitimer(int which, itimerval_t* value)
{
return getitimer(which, value);
}
#endif
time_t Utime__time(time_t* tloc)
{
return time(tloc);
}
time_t Utime__mktime(tm_t* tm)
{
return mktime(tm);
}
char* Utime__ctime(time_t* clock)
{
return ctime(clock);
}
tm_t* Utime__localtime(time_t* clock)
{
return localtime(clock);
}
tm_t* Utime__gmtime(time_t* clock)
{
return gmtime(clock);
}
#ifndef _WIN32
#ifndef __sun /* Solaris ctime_r is different than Posix. */
char* Utime__ctime_r(time_t* clock, char* buffer)
{
return ctime_r(clock, buffer);
}
#endif /* __sun */
tm_t* Utime__localtime_r(time_t* clock, tm_t* result)
{
return localtime_r(clock, result);
}
tm_t* Utime__gmtime_r(time_t* clock, tm_t* result)
{
return gmtime_r(clock, result);
}
int Utime__setitimer(int which, itimerval_t* new_value, itimerval_t* old_value)
{
return setitimer(which, new_value, old_value);
}
#ifndef __INTERIX
int Utime__nanosleep(timespec_T* req, timespec_T* rem)
{
return nanosleep(req, rem);
}
#endif /* __INTERIX */
#endif /* _WIN32 */
void Utime__tzset(void)
{
#ifdef _WIN32
_tzset();
#else
tzset();
#endif
}
#ifdef __cplusplus
} /* extern "C" */
#endif