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