File: get_posix_time.c

package info (click to toggle)
haskell-token-bucket 0.1.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 132 kB
  • sloc: haskell: 132; ansic: 11; makefile: 9
file content (15 lines) | stat: -rw-r--r-- 371 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stddef.h>
#include <math.h>
#include <sys/time.h>
#include <stdint.h>

// returns number of microseconds since epoch; returns 0 in case of error
uint64_t hs_token_bucket_get_posix_time_usecs(void)
{
  struct timeval tval = { 0, 0, };

  if (gettimeofday(&tval, NULL))
    return 0;

  return ((((uint64_t)tval.tv_sec) * 1000000) + ((uint64_t) tval.tv_usec));
}