Bring in some fixes from NetBSD: