From 55bef02069a0a36e883f22e510cf4b2b58129144 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Thu, 9 Apr 2015 22:51:15 +0200 Subject: [PATCH] Restored full cygwin compatibility (win32 should only be used for timing functions with the cygwin layer) --- src/posix-compat.c | 22 +++++++++++----------- src/posix-compat.h | 6 +++++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/posix-compat.c b/src/posix-compat.c index ec1e315..517329e 100644 --- a/src/posix-compat.c +++ b/src/posix-compat.c @@ -1,7 +1,7 @@ #include "posix-compat.h" #include "process.h" -#ifdef _WIN32 +#ifdef VANILLA_WIN32 # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN # include @@ -32,7 +32,7 @@ #include struct proc_handle { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 HANDLE handle; #else pid_t pid; @@ -40,7 +40,7 @@ struct proc_handle { }; struct pipe_handle { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 HANDLE fhs[2]; #else int fds[2]; @@ -49,7 +49,7 @@ struct pipe_handle { struct worker_context g_worker_context = {.test = NULL}; -#ifdef _WIN32 +#ifdef VANILLA_WIN32 static struct criterion_test child_test; static struct criterion_test_extra_data child_test_data; static struct criterion_suite child_suite; @@ -66,7 +66,7 @@ int resume_child(void) { } s_proc_handle *fork_process() { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 PROCESS_INFORMATION info; STARTUPINFOW si = { .cb = sizeof (STARTUPINFOW) }; @@ -117,7 +117,7 @@ s_proc_handle *fork_process() { } void wait_process(s_proc_handle *handle, int *status) { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 WaitForSingleObject(handle->handle, INFINITE); DWORD exit_code; GetExitCodeProcess(handle->handle, &exit_code); @@ -129,7 +129,7 @@ void wait_process(s_proc_handle *handle, int *status) { } FILE *pipe_in(s_pipe_handle *p) { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 CloseHandle(p->fhs[1]); int fd = _open_osfhandle((intptr_t) p->fhs[0], _O_RDONLY); if (fd == -1) @@ -147,7 +147,7 @@ FILE *pipe_in(s_pipe_handle *p) { } FILE *pipe_out(s_pipe_handle *p) { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 CloseHandle(p->fhs[0]); int fd = _open_osfhandle((intptr_t) p->fhs[1], _O_WRONLY); if (fd == -1) @@ -165,7 +165,7 @@ FILE *pipe_out(s_pipe_handle *p) { } s_pipe_handle *stdpipe() { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 HANDLE fhs[2]; SECURITY_ATTRIBUTES attr = { .nLength = sizeof (SECURITY_ATTRIBUTES), .bInheritHandle = TRUE }; if (!CreatePipe(fhs, fhs + 1, &attr, 0)) @@ -180,7 +180,7 @@ s_pipe_handle *stdpipe() { } s_proc_handle *get_current_process() { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 return unique_ptr(s_proc_handle, { GetCurrentProcess() }); #else return unique_ptr(s_proc_handle, { getpid() }); @@ -188,7 +188,7 @@ s_proc_handle *get_current_process() { } bool is_current_process(s_proc_handle *proc) { -#ifdef _WIN32 +#ifdef VANILLA_WIN32 return GetProcessId(proc->handle) == GetProcessId(GetCurrentProcess()); #else return proc->pid == getpid(); diff --git a/src/posix-compat.h b/src/posix-compat.h index 3c32e9c..5faa151 100644 --- a/src/posix-compat.h +++ b/src/posix-compat.h @@ -1,6 +1,10 @@ #ifndef POSIX_COMPAT_H_ # define POSIX_COMPAT_H_ +#if defined(_WIN32) && !defined(__CYGWIN__) +# define VANILLA_WIN32 +#endif + # if !defined(_POSIX_SOURCE) # define _POSIX_SOURCE 1 # define TMP_POSIX @@ -11,7 +15,7 @@ # undef TMP_POSIX # endif -# ifdef _WIN32 +# ifdef VANILLA_WIN32 # define WEXITSTATUS(Status) (((Status) & 0xFF00) >> 8) # define WTERMSIG(Status) ((Status) & 0x7F) # define WIFEXITED(Status) (WTERMSIG(Status) == 0)