Make some Cygwin-specific code more generic