ENGINE-735 implementation of timestamp for Windows

pEpMIME
Volker Birk 3 years ago
parent ca2d4ba76c
commit 3a7e7e15c6

@ -511,7 +511,7 @@ int _append_field(
// http://media2.giga.de/2014/02/Image-28.jpg
struct mailimf_date_time * timestamp_to_etpantime(const struct tm *ts)
struct mailimf_date_time * timestamp_to_etpantime(const timestamp *ts)
{
struct mailimf_date_time * result = calloc(1,
sizeof(struct mailimf_date_time));
@ -527,15 +527,13 @@ struct mailimf_date_time * timestamp_to_etpantime(const struct tm *ts)
result->dt_day = ts->tm_mday;
result->dt_month = ts->tm_mon + 1;
result->dt_year = ts->tm_year + 1900;
#ifndef WIN32
result->dt_zone = (int) (ts->tm_gmtoff / 36L);
#endif
return result;
}
struct tm * etpantime_to_timestamp(const struct mailimf_date_time *et)
timestamp * etpantime_to_timestamp(const struct mailimf_date_time *et)
{
struct tm * result = calloc(1, sizeof(struct tm));
timestamp * result = calloc(1, sizeof(timestamp));
assert(result);
if (result == NULL)
return NULL;
@ -548,9 +546,7 @@ struct tm * etpantime_to_timestamp(const struct mailimf_date_time *et)
result->tm_mday = et->dt_day;
result->tm_mon = et->dt_month - 1;
result->tm_year = et->dt_year - 1900;
#ifndef WIN32
result->tm_gmtoff = 36L * (long) et->dt_zone;
#endif
return result;
}

@ -11,6 +11,7 @@
#include "resource_id.h"
#include "stringpair.h"
#include "timestamp.h"
struct mailmime * part_new_empty(
struct mailmime_content * content,
@ -57,8 +58,8 @@ int _append_field(
void *value
);
struct mailimf_date_time * timestamp_to_etpantime(const struct tm *ts);
struct tm * etpantime_to_timestamp(const struct mailimf_date_time *et);
struct mailimf_date_time * timestamp_to_etpantime(const timestamp *ts);
timestamp * etpantime_to_timestamp(const struct mailimf_date_time *et);
struct mailimf_mailbox * mailbox_from_string(
const char *name,

@ -2701,7 +2701,7 @@ PEP_STATUS pgp_renew_key(
pgp_valid_key_amalgamation_t primary = NULL;
pgp_key_pair_t keypair = NULL;
pgp_signer_t signer = NULL;
time_t t = timegm((struct tm *) ts);
time_t t = timegm((timestamp *) ts); // timestamp because of Windows
pgp_cert_valid_key_iter_t key_iter = NULL;
pgp_valid_key_amalgamation_t ka = NULL;
pgp_packet_t *packets = NULL;

@ -388,6 +388,12 @@ int mkstemp(char *templ)
return _open(pathname, _O_RDWR | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
}
time_t timegm(timestamp *timeptr)
{
time_t result = _mkgmtime((struct tm *) timeptr);
return result += timeptr->tm_gmtoff;
}
void uuid_generate_random(pEpUUID out)
{
RPC_STATUS rpc_status = UuidCreate(out);

@ -53,7 +53,7 @@ int dlclose(void *handle);
void *dlsym(void *handle, const char *symbol);
int mkstemp(char *templ);
#define timegm _mkgmtime
time_t timegm(timestamp *timeptr);
#ifndef strdup
#define strdup(A) _strdup((A))

@ -17,7 +17,7 @@ DYNAMIC_API timestamp * new_timestamp(time_t clock)
return NULL;
if (clock)
gmtime_r(&clock, ts);
gmtime_r(&clock, (struct tm *) ts);
return ts;
}
@ -33,7 +33,7 @@ DYNAMIC_API timestamp * timestamp_dup(const timestamp *src)
if (!src)
return NULL;
timestamp *dst = malloc(sizeof(timestamp));
timestamp *dst = calloc(1, sizeof(timestamp));
assert(dst);
if (!dst)
return NULL;

@ -11,10 +11,24 @@ extern "C" {
#endif
#ifdef WIN32
// this struct is compatible to struct tm
typedef struct _timestamp {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
long tm_gmtoff; // offset from GMT in seconds
} timestamp;
#else
// for time values all functions are using POSIX struct tm
typedef struct tm timestamp;
#endif
// new_timestamp() - allocate a new timestamp
//

Loading…
Cancel
Save