eal/windows: fix MinGW build
[dpdk.git] / lib / eal / windows / include / rte_os_shim.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2
3 #ifndef _RTE_OS_SHIM_
4 #define _RTE_OS_SHIM_
5
6 #include <time.h>
7
8 #include <rte_os.h>
9 #include <rte_windows.h>
10
11 /**
12  * @file
13  * @internal
14  * Provides semi-standard OS facilities by convenient names.
15  */
16
17 #ifndef PATH_MAX
18 #define PATH_MAX _MAX_PATH
19 #endif
20
21 #define strdup(str) _strdup(str)
22 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
23 #ifndef RTE_TOOLCHAIN_GCC
24 #define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
25 #endif
26
27 #define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
28 #define read(fd, buf, n) _read(fd, buf, n)
29 #define write(fd, buf, n) _write(fd, buf, n)
30 #define close(fd) _close(fd)
31 #define unlink(path) _unlink(path)
32
33 #define IPVERSION       4
34
35 #define IPPROTO_IPIP    4
36 #define IPPROTO_GRE     47
37 #ifdef RTE_TOOLCHAIN_GCC
38 #define IPPROTO_SCTP    132
39 #endif
40
41 #ifdef RTE_TOOLCHAIN_GCC
42
43 #define TIME_UTC 1
44
45 static inline int
46 rte_timespec_get(struct timespec *now, int base)
47 {
48         /* 100ns ticks from 1601-01-01 to 1970-01-01 */
49         static const uint64_t EPOCH = 116444736000000000ULL;
50         static const uint64_t TICKS_PER_SEC = 10000000;
51         static const uint64_t NS_PER_TICK = 100;
52
53         FILETIME ft;
54         uint64_t ticks;
55
56         if (base != TIME_UTC)
57                 return 0;
58
59         GetSystemTimePreciseAsFileTime(&ft);
60         ticks = ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
61         ticks -= EPOCH;
62         now->tv_sec = ticks / TICKS_PER_SEC;
63         now->tv_nsec = (ticks - now->tv_sec * TICKS_PER_SEC) * NS_PER_TICK;
64         return base;
65 }
66
67 #define timespec_get(ts, base) rte_timespec_get(ts, base)
68
69 #endif /* RTE_TOOLCHAIN_GCC */
70
71 #endif /* _RTE_OS_SHIM_ */