Replace open/fstat/close with stat

Reduce syscalls by only calling ``stat`` for each filename instead of ``open``, ``fstat``, and ``close``.