510e39e03ba65fc2a6e018dfb692489fbaf7041d
[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
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /* limits.h replacement, value as in <windows.h> */
23 #ifndef PATH_MAX
24 #define PATH_MAX _MAX_PATH
25 #endif
26
27 #define strerror_r(a, b, c) strerror_s(b, c, a)
28
29 /* strdup is deprecated in Microsoft libc and _strdup is preferred */
30 #define strdup(str) _strdup(str)
31
32 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
33
34 #define index(a, b)     strchr(a, b)
35 #define rindex(a, b)    strrchr(a, b)
36
37 #define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
38
39 /* cpu_set macros implementation */
40 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
41 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
42 #define RTE_CPU_FILL(set) CPU_FILL(set)
43 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
44
45 /* as in <windows.h> */
46 typedef long long ssize_t;
47
48 #ifndef RTE_TOOLCHAIN_GCC
49 static inline int
50 asprintf(char **buffer, const char *format, ...)
51 {
52         int size, ret;
53         va_list arg;
54
55         va_start(arg, format);
56         size = vsnprintf(NULL, 0, format, arg);
57         va_end(arg);
58         if (size < 0)
59                 return -1;
60         size++;
61
62         *buffer = malloc(size);
63         if (*buffer == NULL)
64                 return -1;
65
66         va_start(arg, format);
67         ret = vsnprintf(*buffer, size, format, arg);
68         va_end(arg);
69         if (ret != size - 1) {
70                 free(*buffer);
71                 return -1;
72         }
73         return ret;
74 }
75 #endif /* RTE_TOOLCHAIN_GCC */
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif /* _RTE_OS_H_ */