Portability fixes from pkgsrc

Here are some portability fixes from pkgsrc.