From: Bastian Dehn Date: Fri, 17 Jul 2015 16:51:41 +0000 (+0200) Subject: Sortierfunktion nach Dateigroesse X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=16cd94e3b914137eb851f04496724eaed5f78046;p=discspan.git Sortierfunktion nach Dateigroesse --- diff --git a/discspan.c b/discspan.c index b5b1b67..1b1abe1 100644 --- a/discspan.c +++ b/discspan.c @@ -86,6 +86,41 @@ void splitter(const char *input, char *output, const char *rest, unsigned long l printf("Restlicher Platz in Bytes(%s): %lld (%lld %c)\n", output, splitgroesse, humanread, einheit); } +int cmpfunc(const void * a, const void * b) +{ + if(*(long long unsigned int*)a < *(long long unsigned int*)b) + return 1; + if(*(long long unsigned int*)a > *(long long unsigned int*)b) + return -1; + if(*(long long unsigned int*)a == *(long long unsigned int*)b) + return 0; +} + +long long unsigned int * filesize_sort(const char *input, const char *output) +{ + FILE *in; FILE *out; + char pfad[255]; + struct stat st; + int lines = 0; + + in = fopen(input, "r"); + + while(fscanf(in, "%[^\n]\n", pfad) == 1) + { + lines++; + } + fseek(in, 0L, SEEK_SET); + long long unsigned int fsize[lines]; + lines = 0; + while(fscanf(in, "%[^\n]\n", pfad) == 1) + { + stat(pfad, &st); + fsize[lines++] = st.st_size; + } + qsort(fsize, lines, sizeof(unsigned long long), cmpfunc); + return fsize; +} + void usage() { printf("\nUsage: discspan