src/timestamp.c
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:30:19 +0200
branchENGINE-254
changeset 2723 7194b9c8599d
parent 1513 e7f7e42385b5
child 2381 c01f2e8f3582
permissions -rw-r--r--
close branch
vb@1513
     1
// This file is under GNU General Public License 3.0
vb@1513
     2
// see LICENSE.txt
vb@1513
     3
vb@125
     4
#include "pEp_internal.h"
vb@125
     5
vb@124
     6
#include "timestamp.h"
vb@124
     7
vb@124
     8
#include <stdlib.h>
vb@124
     9
#include <string.h>
vb@124
    10
#include <assert.h>
vb@124
    11
vb@124
    12
DYNAMIC_API timestamp * new_timestamp(time_t clock)
vb@124
    13
{
vb@124
    14
    timestamp *ts = calloc(1, sizeof(timestamp));
vb@124
    15
    assert(ts);
vb@124
    16
    if (ts == NULL)
vb@124
    17
        return NULL;
vb@124
    18
vb@124
    19
    if (clock)
vb@124
    20
        gmtime_r(&clock, ts);
vb@124
    21
vb@124
    22
    return ts;
vb@124
    23
}
vb@124
    24
vb@124
    25
vb@124
    26
DYNAMIC_API void free_timestamp(timestamp *ts)
vb@124
    27
{
vb@124
    28
    free(ts);
vb@124
    29
}
vb@124
    30
vb@124
    31
DYNAMIC_API timestamp * timestamp_dup(const timestamp *src)
vb@124
    32
{
vb@124
    33
    timestamp *dst = malloc(sizeof(timestamp));
vb@124
    34
    assert(dst);
vb@124
    35
    if (dst == NULL)
vb@124
    36
        return NULL;
vb@124
    37
vb@124
    38
    memcpy(dst, src, sizeof(timestamp));
vb@124
    39
    return dst;
vb@124
    40
}
vb@124
    41