Browse Source

adding timestamp

doc_update_sequoia
Volker Birk 7 years ago
parent
commit
01f75d7246
2 changed files with 85 additions and 0 deletions
  1. +36
    -0
      src/timestamp.c
  2. +49
    -0
      src/timestamp.h

+ 36
- 0
src/timestamp.c View File

@ -0,0 +1,36 @@
#include "timestamp.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
DYNAMIC_API timestamp * new_timestamp(time_t clock)
{
timestamp *ts = calloc(1, sizeof(timestamp));
assert(ts);
if (ts == NULL)
return NULL;
if (clock)
gmtime_r(&clock, ts);
return ts;
}
DYNAMIC_API void free_timestamp(timestamp *ts)
{
free(ts);
}
DYNAMIC_API timestamp * timestamp_dup(const timestamp *src)
{
timestamp *dst = malloc(sizeof(timestamp));
assert(dst);
if (dst == NULL)
return NULL;
memcpy(dst, src, sizeof(timestamp));
return dst;
}

+ 49
- 0
src/timestamp.h View File

@ -0,0 +1,49 @@
#pragma once
#include <time.h>
#include "dynamic_api.h"
#ifdef __cplusplus
extern "C" {
#endif
// for time values all functions are using POSIX struct tm
typedef struct tm timestamp;
// new_timestamp() - allocate a new timestamp
//
// parameters:
// clock (in) initial value or 0 if not available
//
// return value:
// pointer to timestamp object or NULL if out of memory
DYNAMIC_API timestamp * new_timestamp(time_t clock);
// free_timestamp() - free memory occupied by timestamp
//
// parameters:
// ts (in) pointer to timestamp to free
DYNAMIC_API void free_timestamp(timestamp *ts);
// timestamp_dup() - duplicate a timestamp
//
// parameters:
// src (in) pointer to timestamp to duplicate
//
// return value:
// pointer to copy or NULL if out of memory
DYNAMIC_API timestamp * timestamp_dup(const timestamp *src);
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save