fix Issue 11392 - dirEntries segfaults

This adds back code that https://github.com/D-Programming-Language/dmd/pull/2701 removed, but that I felt shouldn't have been removed, but the rest of it was good.

It also fixes http://d.puremagic.com/issues/show_bug.cgi?id=11392

I'll add a test case for the fix to std.file.