Further factor out OS specific code in compat file.