While here, also use errx from the system on BSDs and don't segfault in strndup if malloc failed. From Don Woodstock in #netbsd-code.