src/timestamp.c
author Dirk Zimmermann <dz@pep.security>
Thu, 11 Apr 2019 10:46:46 +0200
branchIOS-1482
changeset 3505 3fe4b41696d3
parent 2381 c01f2e8f3582
child 3832 8860f25e9be9
permissions -rw-r--r--
IOS-1482 close branch
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include "pEp_internal.h"
     5 
     6 #include "timestamp.h"
     7 
     8 #include <stdlib.h>
     9 #include <string.h>
    10 #include <assert.h>
    11 
    12 DYNAMIC_API timestamp * new_timestamp(time_t clock)
    13 {
    14     timestamp *ts = calloc(1, sizeof(timestamp));
    15     assert(ts);
    16     if (ts == NULL)
    17         return NULL;
    18 
    19     if (clock)
    20         gmtime_r(&clock, ts);
    21 
    22     return ts;
    23 }
    24 
    25 
    26 DYNAMIC_API void free_timestamp(timestamp *ts)
    27 {
    28     free(ts);
    29 }
    30 
    31 DYNAMIC_API timestamp * timestamp_dup(const timestamp *src)
    32 {
    33     assert(src);
    34     if (!src)
    35         return NULL;
    36 
    37     timestamp *dst = malloc(sizeof(timestamp));
    38     assert(dst);
    39     if (!dst)
    40         return NULL;
    41 
    42     memcpy(dst, src, sizeof(timestamp));
    43     return dst;
    44 }
    45