Make alphanum check more terse

Also allows an underscore, which seems harmless.

Result of code review by:

Peter Geoghegan <pg@heroku.com>
Use Postgres fd.h rather than C stdlib

This cleans up all the EINTR handling in particular, which in
turn simplifies buffer management.

Per review by Peter Geoghegan <pg@heroku.com>
Use format string to clean up string manipulation
Cuddle errno check with triggering function

Normally two newlines are expected above a block, but I make a
special exception for errno checking triggered by the antecdent
statement.