src/timestamp.c
changeset 124 e2930c783d3c
child 125 5119178815d8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/timestamp.c	Wed Mar 25 12:55:15 2015 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +#include "timestamp.h"
     1.5 +
     1.6 +#include <stdlib.h>
     1.7 +#include <string.h>
     1.8 +#include <assert.h>
     1.9 +
    1.10 +DYNAMIC_API timestamp * new_timestamp(time_t clock)
    1.11 +{
    1.12 +    timestamp *ts = calloc(1, sizeof(timestamp));
    1.13 +    assert(ts);
    1.14 +    if (ts == NULL)
    1.15 +        return NULL;
    1.16 +
    1.17 +    if (clock)
    1.18 +        gmtime_r(&clock, ts);
    1.19 +
    1.20 +    return ts;
    1.21 +}
    1.22 +
    1.23 +
    1.24 +DYNAMIC_API void free_timestamp(timestamp *ts)
    1.25 +{
    1.26 +    free(ts);
    1.27 +}
    1.28 +
    1.29 +DYNAMIC_API timestamp * timestamp_dup(const timestamp *src)
    1.30 +{
    1.31 +    timestamp *dst = malloc(sizeof(timestamp));
    1.32 +    assert(dst);
    1.33 +    if (dst == NULL)
    1.34 +        return NULL;
    1.35 +
    1.36 +    memcpy(dst, src, sizeof(timestamp));
    1.37 +    return dst;
    1.38 +}
    1.39 +