Add support for multiple GPIO devices (on FreeBSD only), default to device 0.

While here, move some common error handling code into a macro TRYWRITE.
Write all initial error messages to stderr.