X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fdirent%2Fscandir.c;h=7ee195dd8ab31d3cbaf38179aab9a3936b58d711;hb=e858063070eedb7fe78c37eba5177d8c5cfccfa6;hp=6a0a99933833fe531db03216d026f40b4ca6f8d2;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/dirent/scandir.c b/src/dirent/scandir.c index 6a0a9993..7ee195dd 100644 --- a/src/dirent/scandir.c +++ b/src/dirent/scandir.c @@ -1,10 +1,9 @@ #include #include #include -#include +#include #include #include -#include int scandir(const char *path, struct dirent ***res, int (*sel)(const struct dirent *), @@ -12,7 +11,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,25 +25,23 @@ 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); if (errno) { - old_errno = errno; if (names) while (cnt-->0) free(names[cnt]); free(names); - errno = old_errno; return -1; } + errno = old_errno; if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp); *res = names; return cnt; } -LFS64(scandir); +weak_alias(scandir, scandir64);