Remove the static allocation for the dirent, and allocate it from the
heap during opendir().
Removing the static data can reduce RAM usage on some toolchains when
directories are not being used. The static allocation sometimes is
combined with the file handle array and can't be dropped by the linker.
Original readdir() was not thread-safe at all.
This was in violation of POSIX which states the result of readdir "is
not overwritten by another call to readdir() on a different directory
stream."
POSIX also defines readdir_r() as separate totally reentrant form where
the caller allocates the dirent, but this is generally deprecated as it
opens the door for an inadequate allocation causing a stack smash. Full
reentrancy is not typically necessary - having readdir()'s buffer data
be per-DIR is generally sufficient.