forked from ARMmbed/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
22 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters