mirror of
https://github.com/strongswan/strongswan.git
synced 2025-11-27 00:00:29 -05:00
use thread-safe variant of gmtime
This commit is contained in:
parent
6144daba9d
commit
5e5b2dc105
@ -348,8 +348,9 @@ chunk_t asn1_from_time(const time_t *time, asn1_t type)
|
|||||||
const char *format;
|
const char *format;
|
||||||
char buf[BUF_LEN];
|
char buf[BUF_LEN];
|
||||||
chunk_t formatted_time;
|
chunk_t formatted_time;
|
||||||
struct tm *t = gmtime(time);
|
struct tm t;
|
||||||
|
|
||||||
|
gmtime_r(time, &t);
|
||||||
if (type == ASN1_GENERALIZEDTIME)
|
if (type == ASN1_GENERALIZEDTIME)
|
||||||
{
|
{
|
||||||
format = "%04d%02d%02d%02d%02d%02dZ";
|
format = "%04d%02d%02d%02d%02d%02dZ";
|
||||||
@ -358,10 +359,10 @@ chunk_t asn1_from_time(const time_t *time, asn1_t type)
|
|||||||
else /* ASN1_UTCTIME */
|
else /* ASN1_UTCTIME */
|
||||||
{
|
{
|
||||||
format = "%02d%02d%02d%02d%02d%02dZ";
|
format = "%02d%02d%02d%02d%02d%02dZ";
|
||||||
offset = (t->tm_year < 100)? 0 : -100;
|
offset = (t.tm_year < 100)? 0 : -100;
|
||||||
}
|
}
|
||||||
snprintf(buf, BUF_LEN, format, t->tm_year + offset,
|
snprintf(buf, BUF_LEN, format, t.tm_year + offset,
|
||||||
t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
|
t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
|
||||||
formatted_time.ptr = buf;
|
formatted_time.ptr = buf;
|
||||||
formatted_time.len = strlen(buf);
|
formatted_time.len = strlen(buf);
|
||||||
return asn1_simple_object(type, formatted_time);
|
return asn1_simple_object(type, formatted_time);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user