Fix Cygwin crash after injecting hook library.

It looks like Cygwin gets confused by receiving DllMain THREAD_ATTACH
notification when the library is not yet initialized causing it
to later crash. This can be easily reproduced by modifying tup-dllinject
to just CreateRemoteThread which does nothing.

Proposed fix changes injection method from remote thread to code cave
(write stub, adjust eip, resume). This method is safer in overall
because have no side effects of THREAD_ATTACH notification on loaded
libraries.
Implemented stronger function hooking using "hot patching" method.

Original IAT patching approach have a drawback of not intercepting
function calls done dynamically (i.e. GetProcAddress->call). Also it
requires all variants of the function to be hooked instead of single
base one making whole process open to calls not visible to hook.

This fix implements "hot patching" hooking method which inserts redirection
instructions directly to function body if the function is compiled with
"hot patching" compiler switches on. Most functions on recent Windows
versions have this option enabled.

However not all API functions support this method, therefore IAT and hot
patching are both enabled for now. In first pass hot patching redirection
is applied, and then functions which cannot be hooked using redirection are
then patched in import tables (IAT).

In overall this makes hooking much stable for me when using old MingW
/Cygwin tool builds. In long run  IAT patching can be probably dropped
allowing to greatly simplify dllinject.c but that would require
re-organizing list of patched functions.

As a side-effect dllinject.c was refactored a bit into multiple modules.
Fixed fopen with "rb+" mode was always considered as write operation
by hook even if file does not exist and open fails.
Some MingW gcc builds are trying to open some kind of database files
this way (.gcda code coverage?) near output files.
Fixed get_relative_dir() was using POSIX path separators when generating
relative directory string on win32.

Windows shell (cmd.exe) in most cases treats slashes as start of command
parameters, thus making get_relative_dir()-derived paths unusable for
usage in shell scripts on win32.
Fixed win32 API hooks were not preserving GetLastError() value
causing applications to get confused on errors.

For example in my scenario MingW was trying to get information regarding
include folders, but was using buffers which are too small to fit all
information, win32 API was reporting this, but error code was lost in
hook, causing MingW to think that API call failed due to unknown failure
instead of retrying call with bigger buffer.
Implemented colored output for win32.

ANSI escapes are parsed out in compat/win32/printf.c and color commands
are redirected to console API. Also due to using console API directly this
fix greatly improves console output speed of tup - previously printing
thousands of lines was slowing down tup greatly on win32 (i.e. initial
directory scanning was noticeable slow when tup was not redirected to a file).
Merge branch 'hot_patching_inject'
Merge branch 'fopen_rbplus_win32_fix'
Merge branch 'preserve_lasterror_win32_hook'

Conflicts:
	src/dllinject/dllinject.c
Merge branch 'relative_dir_win32'
Merge branch 'win32_colors'