Use per-function errno handling instead of global one.

Requested by:	luigi