sync with upstream: fix build on bsd