blob: db1563b3e09e0fbaa3e7b193eb442262564a6eb9 (
plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*
* Copyright (C) 2017 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <ryadbenadjila@gmail.com>
* Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
* Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
*
* Contributors:
* Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
* Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#include <libecc/external_deps/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;
if (time == NULL) {
ret = -1;
goto err;
}
ret = gettimeofday(&tv, NULL);
if (ret < 0) {
ret = -1;
goto err;
}
(*time) = (u64)(((tv.tv_sec) * 1000) + ((tv.tv_usec) / 1000));
ret = 0;
err:
return ret;
}
/* Windows case */
#elif defined(WITH_STDLIB) && defined(__WIN32__)
#include <stddef.h>
#include <windows.h>
int get_ms_time(u64 *time)
{
int ret;
SYSTEMTIME st;
if (time == NULL) {
ret = -1;
goto err;
}
GetSystemTime(&st);
(*time) = (u64)((((st.wMinute * 60) + st.wSecond) * 1000) + st.wMilliseconds);
ret = 0;
err:
return ret;
}
/* No platform detected, the used must provide an implementation! */
#else
#error "time.c: you have to implement get_ms_time()"
#endif
|