Reintroduce improved fdopen (fixes #52)