pci: keep API compatibility with mmap values
[dpdk.git] / lib / librte_eal / windows / include / rte_os.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2019 Intel Corporation
3  */
4
5 #ifndef _RTE_OS_H_
6 #define _RTE_OS_H_
7
8 /**
9  * This is header should contain any function/macro definition
10  * which are not supported natively or named differently in the
11  * Windows OS. It must not include Windows-specific headers.
12  */
13
14 #include <stdarg.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /* limits.h replacement, value as in <windows.h> */
24 #ifndef PATH_MAX
25 #define PATH_MAX _MAX_PATH
26 #endif
27
28 /* sys/mman.h
29  * The syscall mmap does not exist on Windows,
30  * but this error code is used in a badly defined DPDK API for PCI mapping.
31  */
32 #define MAP_FAILED ((void *) -1)
33
34 #define sleep(x) Sleep(1000 * (x))
35
36 #define strerror_r(a, b, c) strerror_s(b, c, a)
37
38 /* strdup is deprecated in Microsoft libc and _strdup is preferred */
39 #define strdup(str) _strdup(str)
40
41 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
42
43 #define index(a, b)     strchr(a, b)
44 #define rindex(a, b)    strrchr(a, b)
45
46 #define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
47
48 #define close _close
49 #define unlink _unlink
50
51 /* cpu_set macros implementation */
52 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
53 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
54 #define RTE_CPU_FILL(set) CPU_FILL(set)
55 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
56
57 /* as in <windows.h> */
58 typedef long long ssize_t;
59
60 #ifndef RTE_TOOLCHAIN_GCC
61
62 static inline int
63 asprintf(char **buffer, const char *format, ...)
64 {
65         int size, ret;
66         va_list arg;
67
68         va_start(arg, format);
69         size = vsnprintf(NULL, 0, format, arg);
70         va_end(arg);
71         if (size < 0)
72                 return -1;
73         size++;
74
75         *buffer = malloc(size);
76         if (*buffer == NULL)
77                 return -1;
78
79         va_start(arg, format);
80         ret = vsnprintf(*buffer, size, format, arg);
81         va_end(arg);
82         if (ret != size - 1) {
83                 free(*buffer);
84                 return -1;
85         }
86         return ret;
87 }
88
89 static inline const char *
90 eal_strerror(int code)
91 {
92         static char buffer[128];
93
94         strerror_s(buffer, sizeof(buffer), code);
95         return buffer;
96 }
97
98 #define strerror eal_strerror
99
100 #endif /* RTE_TOOLCHAIN_GCC */
101
102 #ifdef __cplusplus
103 }
104 #endif
105
106 #endif /* _RTE_OS_H_ */