forked from ANSSI-FR/libecc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.c
57 lines (48 loc) · 1.26 KB
/
time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (C) 2017 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <[email protected]>
* Arnaud EBALARD <[email protected]>
* Jean-Pierre FLORI <[email protected]>
*
* Contributors:
* Nicolas VIVET <[email protected]>
* Karim KHALFALLAH <[email protected]>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#include "time.h"
/* Unix and compatible case (including macOS) */
#if defined(WITH_STDLIB) && (defined(__unix__) || defined(__APPLE__))
#include <stddef.h>
#include <sys/time.h>
int get_ms_time(u64 *time)
{
struct timeval tv;
int ret;
ret = gettimeofday(&tv, NULL);
if (ret < 0) {
goto err;
}
*time = (u64)(((tv.tv_sec) * 1000) + ((tv.tv_usec) / 1000));
return 0;
err:
return -1;
}
/* Windows case */
#elif defined(WITH_STDLIB) && defined(__WIN32__)
#include <stddef.h>
#include <windows.h>
int get_ms_time(u64 *time)
{
SYSTEMTIME st;
GetSystemTime(&st);
*time = (((st.wMinute * 60) + st.wSecond) * 1000) + st.wMilliseconds;
return 0;
}
/* No platform detected, the used must provide an implementation! */
#else
#error "time.c: you have to implement get_ms_time()"
#endif