Add clock_gettime_heap snippet

This invokes clock_gettime, but uses a timespec from the heap instead
of the stack.
This commit is contained in:
Daniel Kahn Gillmor
2021-03-02 10:26:20 -05:00
parent a92d6ffe7c
commit a3f9410e51
3 changed files with 10 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
struct timespec *ts = malloc(sizeof(struct timespec));
clockid_t ckid = CLOCK_REALTIME;
int ret = clock_gettime(ckid, ts);
if (ret == 0) {
printf("[%s] clock_gettime_heap(CLOCK_REALTIME[%d], ts) -> {%lld, %ld}\n", where, ckid, (long long)ts->tv_sec, ts->tv_nsec);
} else {
printf("[%s] clock_gettime_heap(CLOCK_REALTIME[%d], ts) returned non-zero (%d), errno = %d (%s)\n", where, ckid, ret, errno, strerror(errno));
}

View File

@@ -0,0 +1 @@
FAKETIME 2020-02-02 02:02:02+00:00

View File

@@ -6,3 +6,4 @@
#include <string.h>
#include <errno.h>
#include <time.h>
#include <stdlib.h>