Rework again to copy the struct dirent

Assuming that d_name is the last member of struct dirent.
In POSIX, the maximum length of d_name is defined as NAME_MAX
or FILENAME_MAX though, that assumption may be wrong on some
platforms where defines d_name as the flexible array member
and allocate the minimum memory to store d_name.

Patch from Raimund Steger
This commit is contained in:
Akira TAGOH 2015-02-27 12:04:44 +09:00
parent 1add10bfbc
commit 97cf7ec4d7
1 changed files with 2 additions and 7 deletions

View File

@ -215,13 +215,8 @@ FcScandir (const char *dirp,
{
if (!filter || (filter) (dent))
{
size_t dentlen = sizeof (struct dirent);
if (sizeof (struct dirent) == FcPtrToOffset (dent, dent->d_name))
{
dentlen += strlen (dent->d_name) + 1;
dentlen = ((dentlen + ALIGNOF_VOID_P - 1) & ~(ALIGNOF_VOID_P - 1));
}
size_t dentlen = FcPtrToOffset (dent, dent->d_name) + strlen (dent->d_name) + 1;
dentlen = ((dentlen + ALIGNOF_VOID_P - 1) & ~(ALIGNOF_VOID_P - 1));
p = (struct dirent *) malloc (dentlen);
memcpy (p, dent, dentlen);
if (n >= lsize)