//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
//
//	win32compat.h
//
//	Small compatibility shim that lets the original Windows-oriented
//	Epd2Wb sources build and run on POSIX systems (Linux, macOS, *BSD).
//
//	It provides just the handful of Win32 types/macros/functions that
//	epd2wb.c actually uses:
//
//		BOOL, TRUE, FALSE, DWORD, INFINITE, WAIT_TIMEOUT
//		HANDLE + CreateEvent/SetEvent/WaitForSingleObject/CloseHandle,
//		implemented on top of a pthread mutex/condvar (a Win32 "event").
//		strcmpi -> strcasecmp
//
//	Everything genuinely OS-specific (starting the engine subprocess,
//	reading/writing its pipes, getting the tick count, reporting the
//	last error) is implemented directly in epd2wb.c using normal POSIX
//	calls, rather than being faked up here.
//
//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

#ifndef WIN32COMPAT_H
#define WIN32COMPAT_H

#include <pthread.h>

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

typedef int				BOOL;
typedef unsigned long		DWORD;

#ifndef TRUE
#define	TRUE	1
#endif
#ifndef FALSE
#define	FALSE	0
#endif

#define	INFINITE		0xFFFFFFFFUL
#define	WAIT_TIMEOUT	258
#define	WAIT_OBJECT_0	0

#define	strcmpi			strcasecmp

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

//	A minimal Win32-style auto/manual reset event, backed by a pthread
//	mutex + condition variable.  This is all "epd2wb.c" needs -- it
//	never waits on more than one event at a time, so a full
//	WaitForMultipleObjects-style implementation isn't required.

typedef struct tagEVENT {
	pthread_mutex_t	mutex;
	pthread_cond_t	cond;
	BOOL	fManualReset;
	BOOL	fSignaled;
}	EVENT, * HANDLE;

HANDLE CreateEvent(void * psaAttr, BOOL fManualReset, BOOL fInitialState,
	void * szName);
void SetEvent(HANDLE h);
DWORD WaitForSingleObject(HANDLE h, DWORD dwMilliseconds);
void CloseHandle(HANDLE h);

#endif	//	WIN32COMPAT_H
