Improve compatibility with Solaris.

Fixes #5129