diff options
author | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:44:09 +0000 |
---|---|---|
committer | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:44:09 +0000 |
commit | 4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b (patch) | |
tree | acd4001a266a8713495af7f1b2102b61e67113b0 /mdk-stage1/dietlibc/libcruft/scandir64.c | |
parent | 71b111ec6c4671667a19c6fbe0023d33422535d7 (diff) | |
download | drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.gz drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.bz2 drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.xz drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.zip |
Import dietlibc 0.22 + other fixes for AMD64
Diffstat (limited to 'mdk-stage1/dietlibc/libcruft/scandir64.c')
-rw-r--r-- | mdk-stage1/dietlibc/libcruft/scandir64.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/libcruft/scandir64.c b/mdk-stage1/dietlibc/libcruft/scandir64.c new file mode 100644 index 000000000..c1bdc3415 --- /dev/null +++ b/mdk-stage1/dietlibc/libcruft/scandir64.c @@ -0,0 +1,47 @@ +#include <stdlib.h> +#include <dirent.h> +#include <string.h> + +int scandir64(const char *dir, struct dirent64 ***namelist, + int (*select)(const struct dirent64 *), + int (*compar)(const struct dirent64 **, const struct dirent64 **)) { + DIR* d; + struct dirent64 *D; + int num=0; + if (!(d=opendir(dir))) + return -1; + *namelist=0; + while ((D=readdir64(d))) { + if (select==0 || select(D)) { + struct dirent64 **tmp; + ++num; +/* printf("realloc %p,%d -> ",*namelist,num*sizeof(struct dirent**)); */ + if (!(tmp=realloc(*namelist,num*sizeof(struct dirent64**))) || + !(tmp[num-1]=malloc(sizeof(struct dirent64)))) { + int i; + for (i=0; i<num-1; ++i) free(tmp[i]); + free(*namelist); + closedir(d); + return -1; + } + memccpy(tmp[num-1]->d_name,D->d_name,0,NAME_MAX); + *namelist=tmp; +/* printf("%p; tmp[num-1(%d)]=%p\n",*namelist,num-1,tmp[num-1]); */ + } + } + closedir(d); +#if 0 + { + int i; + puts("pre-qsort:\n"); + for (i=0; i<num-1; ++i) { + puts((*namelist)[i]->d_name); + } + puts("post-qsort:\n"); + } +#endif +// qsort(&(*namelist)[0],num,sizeof(struct dirent*),(int (*)(const void*,const void*))(compar)); + if (compar) + qsort(*namelist,num,sizeof(struct dirent64*),(int (*)(const void*,const void*))(compar)); + return num; +} |