getenv_f(): fix handling of too short buffers