22 lines551 BC
1/* host shim for tools/https_test.c: lv2's clock and random numbers on Linux */
2#ifndef SHIM_LV2_SYSTIME_H
3#define SHIM_LV2_SYSTIME_H
4#include <stdint.h>
5#include <stdio.h>
6#include <time.h>
7
8static inline uint64_t sysGetSystemTime(void)
9{
10 struct timespec ts;
11 clock_gettime(CLOCK_MONOTONIC, &ts);
12 return (uint64_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
13}
14
15static inline int sysGetRandomNumber(void *buf, size_t n)
16{
17 FILE *f = fopen("/dev/urandom", "rb");
18 int ok = f && fread(buf, 1, n, f) == n;
19 if (f) fclose(f);
20 return ok ? 0 : -1;
21}
22#endif