eal/windows: add some basic functions and macros
[dpdk.git] / lib / librte_eal / windows / eal / 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 static inline int
61 asprintf(char **buffer, const char *format, ...)
62 {
63         int size, ret;
64         va_list arg;
65
66         va_start(arg, format);
67         size = vsnprintf(NULL, 0, format, arg) + 1;
68         va_end(arg);
69
70         *buffer = malloc(size);
71         if (buffer == NULL)
72                 printf("Cannot allocate memory");
73
74         va_start(arg, format);
75         ret = vsnprintf(*buffer, size, format, arg);
76         va_end(arg);
77         if (ret != size - 1) {
78                 free(*buffer);
79                 return -1;
80         }
81         return ret;
82 }
83
84 /* cpu_set macros implementation */
85 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
86 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
87 #define RTE_CPU_FILL(set) CPU_FILL(set)
88 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
89
90 #ifdef __cplusplus
91 }
92 #endif
93
94 #endif /* _RTE_OS_H_ */