src/timestamp.c
author Volker Birk <vb@pep.foundation>
Wed, 29 Aug 2018 17:10:23 +0200
branchsync
changeset 2899 63b619aef131
parent 2381 c01f2e8f3582
child 3832 8860f25e9be9
permissions -rw-r--r--
somewhat bigger
vb@1517
     1
// This file is under GNU General Public License 3.0
vb@1517
     2
// see LICENSE.txt
vb@1517
     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@2381
    33
    assert(src);
vb@2381
    34
    if (!src)
vb@2381
    35
        return NULL;
vb@2381
    36
vb@124
    37
    timestamp *dst = malloc(sizeof(timestamp));
vb@124
    38
    assert(dst);
vb@2381
    39
    if (!dst)
vb@124
    40
        return NULL;
vb@124
    41
vb@124
    42
    memcpy(dst, src, sizeof(timestamp));
vb@124
    43
    return dst;
vb@124
    44
}
vb@124
    45