- remove dependency on Windows headers Signed-off-by: SSE4 <tomskside@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
diff --git a/sys/wait.h b/sys/wait.h
index 5a67880..ccdbab7 100644
--- a/sys/wait.h
+++ b/sys/wait.h
@@ -37,19 +37,125 @@ SOFTWARE.
extern "C" {
#endif /* __cplusplus */
-#include <Windows.h>
-
-#ifdef _MSC_VER
-#include <winsock.h> /* for timeval */
-#endif /* _MSC_VER */
-
#ifdef __GNUC__
#include <sys/time.h> /* for timeval */
#endif /* __GNUC__ */
#include <errno.h>
+#include <string.h>
+
+#ifndef _INC_WINDOWS
+
+typedef unsigned long DWORD;
+typedef DWORD * LPDWORD;
+typedef long long LONG_PTR;
+typedef unsigned long long ULONG_PTR;
+typedef long LONG;
+typedef wchar_t WCHAR;
+typedef int BOOL;
+typedef void VOID;
+typedef void * HANDLE;
+
+#ifndef MAX_PATH
+#define MAX_PATH 260
+#endif /* MAX_PATH */
+
+#ifndef WINAPI
+#define WINAPI __stdcall
+#endif /* WINAPI */
+
+#ifndef DECLSPEC_DLLIMPORT
+#ifdef _MSC_VER
+#define DECLSPEC_DLLIMPORT __declspec(dllimport)
+#else /* _MSC_VER */
+#define DECLSPEC_DLLIMPORT
+#endif /* _MSC_VER */
+#endif /* DECLSPEC_DLLIMPORT */
+
+#ifndef WINBASEAPI
+#define WINBASEAPI DECLSPEC_DLLIMPORT
+#endif /* WINBASEAPI */
+
+#ifndef INVALID_HANDLE_VALUE
+#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
+#endif /* INVALID_HANDLE_VALUE */
+
+#ifndef SYNCHRONIZE
+#define SYNCHRONIZE (0x00100000L)
+#endif /* SYNCHRONIZE */
+
+#ifndef PROCESS_QUERY_INFORMATION
+#define PROCESS_QUERY_INFORMATION (0x0400)
+#endif /* PROCESS_QUERY_INFORMATION */
+
+#ifndef INFINITE
+#define INFINITE 0xFFFFFFFF
+#endif /* INFINITE */
+
+#ifndef WAIT_OBJECT_0
+#define WAIT_OBJECT_0 0
+#endif /* WAIT_OBJECT_0 */
+
+#ifndef WAIT_TIMEOUT
+#define WAIT_TIMEOUT 258L
+#endif /* WAIT_TIMEOUT */
-#include <TlHelp32.h>
+typedef struct private_FILETIME {
+ DWORD dwLowDateTime;
+ DWORD dwHighDateTime;
+} private_FILETIME, *private_PFILETIME, *private_LPFILETIME;
+
+#define FILETIME private_FILETIME
+#define PFILETIME private_PFILETIME
+#define LPFILETIME private_LPFILETIME
+
+WINBASEAPI DWORD WINAPI GetCurrentProcessId(VOID);
+WINBASEAPI BOOL WINAPI CloseHandle(HANDLE hObject);
+WINBASEAPI HANDLE WINAPI OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId);
+WINBASEAPI DWORD WINAPI WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds);
+WINBASEAPI BOOL WINAPI GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode);
+WINBASEAPI BOOL WINAPI GetProcessTimes(HANDLE hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
+
+#endif /* _INC_WINDOWS */
+
+#ifndef _WINSOCKAPI_
+
+struct private_timeval {
+ long tv_sec;
+ long tv_usec;
+};
+
+#define timeval private_timeval
+
+#endif /* _WINSOCKAPI_ */
+
+#ifndef _INC_TOOLHELP32
+
+typedef struct tagPROCESSENTRY32W
+{
+ DWORD dwSize;
+ DWORD cntUsage;
+ DWORD th32ProcessID;
+ ULONG_PTR th32DefaultHeapID;
+ DWORD th32ModuleID;
+ DWORD cntThreads;
+ DWORD th32ParentProcessID;
+ LONG pcPriClassBase;
+ DWORD dwFlags;
+ WCHAR szExeFile[MAX_PATH];
+} PROCESSENTRY32W;
+typedef PROCESSENTRY32W * PPROCESSENTRY32W;
+typedef PROCESSENTRY32W * LPPROCESSENTRY32W;
+
+#ifndef TH32CS_SNAPPROCESS
+#define TH32CS_SNAPPROCESS 2
+#endif /* TH32CS_SNAPPROCESS */
+
+HANDLE WINAPI CreateToolhelp32Snapshot(DWORD dwFlags, DWORD th32ProcessID);
+BOOL WINAPI Process32FirstW(HANDLE hSnapshot, LPPROCESSENTRY32W lppe);
+BOOL WINAPI Process32NextW(HANDLE hSnapshot, LPPROCESSENTRY32W lppe);
+
+#endif /* _INC_TOOLHELP32 */
#ifndef WNOHANG
#define WNOHANG 1
@@ -196,19 +302,19 @@ idtype_t;
#endif /* _XOPEN_SOURCE */
-inline int __filter_anychild(PROCESSENTRY32 * pe, DWORD pid)
+inline int __filter_anychild(PROCESSENTRY32W * pe, DWORD pid)
{
return pe->th32ParentProcessID == GetCurrentProcessId();
}
-inline int __filter_pid(PROCESSENTRY32 * pe, DWORD pid)
+inline int __filter_pid(PROCESSENTRY32W * pe, DWORD pid)
{
return pe->th32ProcessID == pid;
}
inline void __filetime2timeval(FILETIME time, struct timeval * out)
{
- ULONGLONG value = time.dwHighDateTime;
+ unsigned long long value = time.dwHighDateTime;
value = (value << 32) | time.dwLowDateTime;
out->tv_sec = (long)(value / 1000000);
out->tv_usec = (long)(value % 1000000);
@@ -218,8 +324,8 @@ inline int __waitpid_internal(pid_t pid, int * status, int options, siginfo_t *
{
int saved_status = 0;
HANDLE hProcess = INVALID_HANDLE_VALUE, hSnapshot = INVALID_HANDLE_VALUE;
- int (*filter)(PROCESSENTRY32*, DWORD);
- PROCESSENTRY32 pe;
+ int (*filter)(PROCESSENTRY32W*, DWORD);
+ PROCESSENTRY32W pe;
DWORD wait_status = 0, exit_code = 0;
int nohang = WNOHANG == (WNOHANG & options);
options &= ~(WUNTRACED | __WNOWAIT | __WCONTINUED | WNOHANG);
@@ -257,7 +363,7 @@ inline int __waitpid_internal(pid_t pid, int * status, int options, siginfo_t *
return -1;
}
pe.dwSize = sizeof(pe);
- if (!Process32First(hSnapshot, &pe))
+ if (!Process32FirstW(hSnapshot, &pe))
{
CloseHandle(hSnapshot);
errno = ECHILD;
@@ -267,7 +373,7 @@ inline int __waitpid_internal(pid_t pid, int * status, int options, siginfo_t *
{
if (filter(&pe, pid))
{
- hProcess = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION, FALSE, pe.th32ProcessID);
+ hProcess = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION, 0, pe.th32ProcessID);
if (INVALID_HANDLE_VALUE == hProcess)
{
CloseHandle(hSnapshot);
@@ -277,7 +383,7 @@ inline int __waitpid_internal(pid_t pid, int * status, int options, siginfo_t *
break;
}
}
- while (Process32Next(hSnapshot, &pe));
+ while (Process32NextW(hSnapshot, &pe));
if (INVALID_HANDLE_VALUE == hProcess)
{
CloseHandle(hSnapshot);
@@ -364,6 +470,22 @@ inline pid_t wait4(pid_t pid, int * status, int options, struct rusage * rusage)
#endif /* _XOPEN_SOURCE */
+#ifndef _INC_WINDOWS
+
+#undef WAIT_OBJECT_0
+
+#undef FILETIME
+#undef PFILETIME
+#undef LPFILETIME
+
+#endif /* _INC_WINDOWS */
+
+#ifndef _WINSOCKAPI_
+
+#undef timeval
+
+#endif /* _WINSOCKAPI_ */
+
#ifdef __cplusplus
}
#endif /* __cplusplus */