Work around fdopendir() missing on some platforms.
(cherry picked from commit 19be8b73b5ee94b890ca09ccf7346ea923b36c1c)
Merge pull request #1118 from kacfengine/safe_open_3.5.x

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