src/timestamp.c
author Volker Birk <vb@pep-project.org>
Wed, 25 Mar 2015 12:55:15 +0100
changeset 124 e2930c783d3c
child 125 5119178815d8
permissions -rw-r--r--
adding timestamp
vb@124
     1
#include "timestamp.h"
vb@124
     2
vb@124
     3
#include <stdlib.h>
vb@124
     4
#include <string.h>
vb@124
     5
#include <assert.h>
vb@124
     6
vb@124
     7
DYNAMIC_API timestamp * new_timestamp(time_t clock)
vb@124
     8
{
vb@124
     9
    timestamp *ts = calloc(1, sizeof(timestamp));
vb@124
    10
    assert(ts);
vb@124
    11
    if (ts == NULL)
vb@124
    12
        return NULL;
vb@124
    13
vb@124
    14
    if (clock)
vb@124
    15
        gmtime_r(&clock, ts);
vb@124
    16
vb@124
    17
    return ts;
vb@124
    18
}
vb@124
    19
vb@124
    20
vb@124
    21
DYNAMIC_API void free_timestamp(timestamp *ts)
vb@124
    22
{
vb@124
    23
    free(ts);
vb@124
    24
}
vb@124
    25
vb@124
    26
DYNAMIC_API timestamp * timestamp_dup(const timestamp *src)
vb@124
    27
{
vb@124
    28
    timestamp *dst = malloc(sizeof(timestamp));
vb@124
    29
    assert(dst);
vb@124
    30
    if (dst == NULL)
vb@124
    31
        return NULL;
vb@124
    32
vb@124
    33
    memcpy(dst, src, sizeof(timestamp));
vb@124
    34
    return dst;
vb@124
    35
}
vb@124
    36