eal: move OS-specific sub-directories
[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. Functions will be added in future releases.
12  */
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 #include <windows.h>
19 #include <basetsd.h>
20 #include <pthread.h>
21 #include <stdio.h>
22
23 /* limits.h replacement */
24 #include <stdlib.h>
25 #ifndef PATH_MAX
26 #define PATH_MAX _MAX_PATH
27 #endif
28
29 #define strerror_r(a, b, c) strerror_s(b, c, a)
30
31 /* strdup is deprecated in Microsoft libc and _strdup is preferred */
32 #define strdup(str) _strdup(str)
33
34 typedef SSIZE_T ssize_t;
35
36 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
37
38 #define index(a, b)     strchr(a, b)
39 #define rindex(a, b)    strrchr(a, b)
40
41 #define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
42
43 /**
44  * Create a thread.
45  * This function is private to EAL.
46  *
47  * @param thread
48  *   The location to store the thread id if successful.
49  * @return
50  *   0 for success, -1 if the thread is not created.
51  */
52 int eal_thread_create(pthread_t *thread);
53
54 /**
55  * Create a map of processors and cores on the system.
56  * This function is private to EAL.
57  */
58 void eal_create_cpu_map(void);
59
60 #ifndef RTE_TOOLCHAIN_GCC
61 static inline int
62 asprintf(char **buffer, const char *format, ...)
63 {
64         int size, ret;
65         va_list arg;
66
67         va_start(arg, format);
68         size = vsnprintf(NULL, 0, format, arg);
69         va_end(arg);
70         if (size < 0)
71                 return -1;
72         size++;
73
74         *buffer = malloc(size);
75         if (*buffer == NULL)
76                 return -1;
77
78         va_start(arg, format);
79         ret = vsnprintf(*buffer, size, format, arg);
80         va_end(arg);
81         if (ret != size - 1) {
82                 free(*buffer);
83                 return -1;
84         }
85         return ret;
86 }
87 #endif /* RTE_TOOLCHAIN_GCC */
88
89 /* cpu_set macros implementation */
90 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
91 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
92 #define RTE_CPU_FILL(set) CPU_FILL(set)
93 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
94
95 #ifdef __cplusplus
96 }
97 #endif
98
99 #endif /* _RTE_OS_H_ */