X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fdirent%2Fscandir.c;h=3af2b50f81920aeba1fa2731b44cf8aa19fa5140;hb=2068b4e8911a3a49cded44b4568f6c943a8c98f8;hp=aad813ac792b574b02d32b8d2b50eb2fd391d483;hpb=dae17a1aaf25d8333e729173d86659066607d87d;p=musl diff --git a/src/dirent/scandir.c b/src/dirent/scandir.c index aad813ac..3af2b50f 100644 --- a/src/dirent/scandir.c +++ b/src/dirent/scandir.c @@ -1,10 +1,10 @@ #include #include #include -#include +#include #include #include -#include +#include "libc.h" int scandir(const char *path, struct dirent ***res, int (*sel)(const struct dirent *), @@ -12,7 +12,7 @@ int scandir(const char *path, struct dirent ***res, { DIR *d = opendir(path); struct dirent *de, **names=0, **tmp; - size_t cnt=0, len=0, size; + size_t cnt=0, len=0; int old_errno = errno; if (!d) return -1; @@ -26,10 +26,9 @@ int scandir(const char *path, struct dirent ***res, if (!tmp) break; names = tmp; } - size = offsetof(struct dirent,d_name) + strlen(de->d_name) + 1; - names[cnt] = malloc(size); + names[cnt] = malloc(de->d_reclen); if (!names[cnt]) break; - memcpy(names[cnt++], de, size); + memcpy(names[cnt++], de, de->d_reclen); } closedir(d);