Fix CYGWIN build.
Improve portability checks.

This fix some compiling issues on CYGWIN.