Work around fdopendir() missing on some platforms.
Merge pull request #1117 from kacfengine/safe_open

Work around fdopendir() missing on some platforms.