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