fdopen for all os platforms, to fix unclosed file issue