Enable C99 mode.

The -D_FOO_SOURCE are needed to expose the various library routine
prototypes, otherwise C99 is a pretty blank slate.
Use C99 loop variable declarations, and mixed declarations and code.

Allows narrowing the scope, and introducing variables when they
are needed.
Narrow scope.
Move errno warning closer to the failure.