portability fixes for NetBSD (issue #5151)