Improve portability
Merge pull request #5437 from veger/posix-fix

Improve portability