Fix compile on BSD systems

This replaces #642.