eal/windows: fix debug build with MinGW
[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 #ifndef sleep
29 #define sleep(x) Sleep(1000 * (x))
30 #endif
31
32 #ifndef strerror_r
33 #define strerror_r(a, b, c) strerror_s(b, c, a)
34 #endif
35
36 #ifndef strdup
37 /* strdup is deprecated in Microsoft libc and _strdup is preferred */
38 #define strdup(str) _strdup(str)
39 #endif
40
41 #ifndef strtok_r
42 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
43 #endif
44
45 #ifndef index
46 #define index(a, b)     strchr(a, b)
47 #endif
48
49 #ifndef rindex
50 #define rindex(a, b)    strrchr(a, b)
51 #endif
52
53 #ifndef strncasecmp
54 #define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
55 #endif
56
57 #ifndef close
58 #define close _close
59 #endif
60
61 #ifndef unlink
62 #define unlink _unlink
63 #endif
64
65 /* cpu_set macros implementation */
66 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
67 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
68 #define RTE_CPU_FILL(set) CPU_FILL(set)
69 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
70
71 /* as in <windows.h> */
72 typedef long long ssize_t;
73
74 #ifndef RTE_TOOLCHAIN_GCC
75
76 static inline int
77 asprintf(char **buffer, const char *format, ...)
78 {
79         int size, ret;
80         va_list arg;
81
82         va_start(arg, format);
83         size = vsnprintf(NULL, 0, format, arg);
84         va_end(arg);
85         if (size < 0)
86                 return -1;
87         size++;
88
89         *buffer = malloc(size);
90         if (*buffer == NULL)
91                 return -1;
92
93         va_start(arg, format);
94         ret = vsnprintf(*buffer, size, format, arg);
95         va_end(arg);
96         if (ret != size - 1) {
97                 free(*buffer);
98                 return -1;
99         }
100         return ret;
101 }
102
103 static inline const char *
104 eal_strerror(int code)
105 {
106         static char buffer[128];
107
108         strerror_s(buffer, sizeof(buffer), code);
109         return buffer;
110 }
111
112 #ifndef strerror
113 #define strerror eal_strerror
114 #endif
115
116 #endif /* RTE_TOOLCHAIN_GCC */
117
118 #ifdef __cplusplus
119 }
120 #endif
121
122 #endif /* _RTE_OS_H_ */