Add POSIX support and fix some cross-platform issues