[3.5.x] Work around fdopendir() missing on some platforms.

(cherry picked from commit 19be8b73b5ee94b890ca09ccf7346ea923b36c1c)