Also fix typo in SYS_open check and use _XOPEN_SOURCE=500 for SunOS in order to get prototype for things like snprintf().