protect against bad fd in fdopen and fp in fseek